public void Dispose() { var stack = new NativeStack <int>(Allocator.Temp); Assert.IsTrue(stack.IsCreated); stack.Dispose(); Assert.IsFalse(stack.IsCreated); Assert.Throws <System.ObjectDisposedException>(() => { stack.Dispose(); }); stack = new NativeStack <int>(Allocator.TempJob); Assert.IsTrue(stack.IsCreated); stack.Dispose(default).Complete();
public unsafe void Test() { const int cnt = 1000; using var stack = new NativeStack <int>(0); var managed = new Stack <int>(cnt); var arr = new int[cnt]; var rand = new Random(); for (int i = 0; i < cnt; i++) { arr[i] = rand.Next(cnt); } for (int i = 0; i < cnt; i++) { managed.Push(arr[i]); stack.Push(arr[i]); } var se = stack.GetEnumerator(); var me = managed.GetEnumerator(); for (var i = 0; i < cnt; i++) { se.MoveNext(); me.MoveNext(); Assert.True(se.Current == me.Current); } se.Dispose(); me.Dispose(); for (int i = 0; i < cnt; i++) { Assert.True(managed.Count == stack.Count); var l = managed.Pop(); var r = stack.Peek(); Assert.True(l == r); stack.Pop(); } stack.Clear(); stack.TrimExcess(); Assert.True(!stack.IsDisposed); stack.Dispose(); Assert.True(stack.Ptr == null); Assert.True(stack.IsDisposed); }
public void IsEmpty() { var stack = new NativeStack <int>(Allocator.Temp); Assert.AreEqual(0, stack.Count); Assert.IsTrue(stack.IsEmpty); stack.Push(0); stack.Pop(); Assert.AreEqual(0, stack.Count); Assert.IsTrue(stack.IsEmpty); stack.Push(1); stack.Push(2); stack.Clear(); Assert.AreEqual(0, stack.Count); Assert.IsTrue(stack.IsEmpty); stack.Dispose(); }
public void Dispose() { _stack.Dispose(); UnsafeUtility.Free(_comparer, _allocator); }