public unsafe void TempAllocatorRenestingUserNull() { void *[] mem = new void *[4096]; for (int j = 0; j < 2; j++) { for (int i = 0; i < mem.Length; i++) { UnsafeUtility.EnterTempScope(); if (j == 0) { UnsafeUtility.SetTempScopeUser((void *)(i + 1)); } else { Assert.IsTrue(UnsafeUtility.GetTempScopeUser() == null); } mem[i] = UnsafeUtility.Malloc(4096, 0, Collections.Allocator.Temp); } for (int i = mem.Length - 1; i >= 0; i--) { UnsafeUtility.Free(mem[i], Collections.Allocator.Temp); UnsafeUtility.ExitTempScope(); } } }
private static unsafe void ReleaseScopeSafetyHandle() { void *user = UnsafeUtility.GetTempScopeUser(); AtomicSafetyHandle.Release(*(AtomicSafetyHandle *)user); UnsafeUtility.Free(user, Allocator.Temp); UnsafeUtility.SetTempScopeUser(null); }
public unsafe void TempAllocatorNullIfNoScope() { ExitTempScopesLocally(); // Try to alloc Assert.IsTrue(UnsafeUtility.Malloc(24, 0, Collections.Allocator.Temp) == null); // Try get user Assert.IsTrue(UnsafeUtility.GetTempScopeUser() == null); EnterTempScopesLocally(); }
public unsafe void TempAllocatorRewindSavesUserData() { void *[] mem = new void *[4096]; for (int i = 0; i < mem.Length; i++) { UnsafeUtility.EnterTempScope(); UnsafeUtility.SetTempScopeUser((void *)(i + 1)); mem[i] = UnsafeUtility.Malloc(4096, 0, Collections.Allocator.Temp); } for (int i = mem.Length - 1; i >= 0; i--) { Assert.IsTrue((void *)(i + 1) == UnsafeUtility.GetTempScopeUser()); UnsafeUtility.Free(mem[i], Collections.Allocator.Temp); UnsafeUtility.ExitTempScope(); } }
internal static unsafe AtomicSafetyHandle GetSafetyHandle() { void *user = UnsafeUtility.GetTempScopeUser(); return(*(AtomicSafetyHandle *)user); }