public void StackAllocatorWorks() { AllocatorManager.Initialize(); var origin = AllocatorManager.Persistent; var backingStorage = origin.AllocateBlock(default(byte), 100000); // allocate a block of bytes from Malloc.Persistent var allocator = new AllocatorManager.StackAllocator(backingStorage); const int kLength = 100; for (int i = 1; i < kLength; ++i) { var block = allocator.AllocateBlock(default(int), i); Assert.AreNotEqual(IntPtr.Zero, block.Range.Pointer); Assert.AreEqual(i, block.Range.Items); Assert.AreEqual(UnsafeUtility.SizeOf <int>(), block.BytesPerItem); Assert.AreEqual(UnsafeUtility.AlignOf <int>(), block.Alignment); allocator.FreeBlock(ref block); } allocator.Dispose(); backingStorage.Dispose(); AllocatorManager.Shutdown(); }
public unsafe void ReleasingChildAllocatorsWorks() { AllocatorManager.Initialize(); var origin = AllocatorManager.Persistent; var parentStorage = origin.AllocateBlock(default(byte), 100000); // allocate a block of bytes from Malloc.Persistent var parent = new AllocatorManager.StackAllocator(parentStorage); // and make a stack allocator from it var childStorage = parent.AllocateBlock(default(byte), 10000); // allocate some space from the parent var child = new AllocatorManager.StackAllocator(childStorage); // and make a stack allocator from it parent.Dispose(); // tear down the parent allocator Assert.Throws <ArgumentException>(() => { child.Allocate(default(byte), 1000); // try to allocate from the child - it should fail. }); parentStorage.Dispose(); AllocatorManager.Shutdown(); }