//[Repeat( 25 )] public void AtomicFreeList() { using (var freeList = new UnsafeAtomicFreeList(1024, Allocator.Persistent)) { var job = new FreeJob { freeList = freeList }; job.Schedule(1024 * 100, 1).Complete(); var foo = new HashSet <int>(); for (int i = 0; i < freeList.Capacity; ++i) { var idx = freeList.Pop(); Assert.IsTrue(idx < 1024 && idx >= 0); Assert.IsFalse(foo.Contains(idx)); } Assert.AreEqual(-1, freeList.Pop()); } }
public void AllocatesAndFreesFromBurst() { AllocatorManager.Initialize(); const int kLength = 100; using (var blocks = new NativeArray <AllocatorManager.Block>(kLength, Allocator.Persistent)) { var allocateJob = new AllocateJob(); allocateJob.m_blocks = blocks; allocateJob.Schedule(kLength, 1).Complete(); for (int i = 0; i < kLength; ++i) { var block = allocateJob.m_blocks[i]; if (i != 0) { 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); Assert.AreEqual(AllocatorManager.Persistent.Value, block.Range.Allocator.Value); } var freeJob = new FreeJob(); freeJob.m_blocks = blocks; freeJob.Schedule(kLength, 1).Complete(); for (int i = 0; i < kLength; ++i) { var block = allocateJob.m_blocks[i]; Assert.AreEqual(IntPtr.Zero, block.Range.Pointer); Assert.AreEqual(0, block.Range.Items); Assert.AreEqual(UnsafeUtility.SizeOf <int>(), block.BytesPerItem); Assert.AreEqual(UnsafeUtility.AlignOf <int>(), block.Alignment); Assert.AreEqual(AllocatorManager.Persistent.Value, block.Range.Allocator.Value); } } AllocatorManager.Shutdown(); }