예제 #1
0
        public unsafe void Dispose()
        {
            if (_queue != null)
            {
#if ENABLE_THREAD_SAFE_CHECKS
                //todo: this must be unit tested
                if (Interlocked.CompareExchange(ref _threadSentinel, 1, 0) != 0)
                {
                    throw new Exception("NativeBag is not thread safe, reading and writing operations can happen" +
                                        "on different threads, but not simultaneously");
                }

                try
                {
#endif
                _queue->Dispose();
                MemoryUtilities.Free((IntPtr)_queue, _queue->allocator);
                _queue = null;
#if ENABLE_THREAD_SAFE_CHECKS
            }
            finally
            {
                Volatile.Write(ref _threadSentinel, 0);
            }
#endif
            }
        }
 public void Dispose()
 {
     for (int i = 0; i < _threadsCount; i++)
     {
         GetBuffer(i).Dispose();
     }
     MemoryUtilities.Free((IntPtr)_data, _allocator);
 }
예제 #3
0
 public unsafe void Dispose()
 {
     if (_queue != null)
     {
         _queue->Dispose();
         MemoryUtilities.Free((IntPtr)_queue, _queue->allocator);
         _queue = null;
     }
 }
예제 #4
0
 public void Dispose()
 {
     unsafe {
         if (data != null)
         {
             MemoryUtilities.Free((IntPtr)data, _allocator);
             data = null;
         }
     }
 }
예제 #5
0
        public void Dispose()
        {
            if (_data == null)
            {
                throw new Exception("using invalid AtomicNativeBags");
            }

            for (int i = 0; i < _threadsCount; i++)
            {
                GetBuffer(i).Dispose();
            }
            MemoryUtilities.Free((IntPtr)_data, _allocator);
            _data = null;
        }
예제 #6
0
        public unsafe void Dispose()
        {
            if (_queue != null)
            {
                BasicTests();

                using (_threadSentinel.TestThreadSafety())
                {
                    _queue->Dispose();
                    MemoryUtilities.Free((IntPtr)_queue, _queue->allocator);
                    _queue = null;
                }
            }
        }
예제 #7
0
 public void TestResize()
 {
     unsafe
     {
         var ptr = MemoryUtilities.Alloc(10, Allocator.Persistent);
         Unsafe.Write((void *)ptr, new Test()
         {
             a   = 3
             , b = 1
         });
         Unsafe.Write((void *)(ptr + 8), (short)-10);
         ptr = MemoryUtilities.Realloc(ptr, 10, Allocator.Persistent, 16);
         var test = Unsafe.Read <Test>((void *)ptr);
         Assert.That(test.a == 3);
         Assert.That(test.b == 1);
         Assert.That(Unsafe.Read <short>((void *)(ptr + 8)) == -10);
         MemoryUtilities.Free(ptr, Allocator.Persistent);
     }
 }