コード例 #1
0
        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();
コード例 #2
0
ファイル: TestNativeStack.cs プロジェクト: ksgfk/KSGFK.Unsafe
        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);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
 public void Dispose()
 {
     _stack.Dispose();
     UnsafeUtility.Free(_comparer, _allocator);
 }