예제 #1
0
 /// <summary>
 /// Decrements the number of views that uses this memory block as storage.
 /// </summary>
 private void DecrementViewCount()
 {
     if (Interlocked.Decrement(ref _viewCount) == 0 && _sharedMemory != IntPtr.Zero && !_isMirror)
     {
         MemoryManagement.DestroySharedMemory(_sharedMemory);
         _sharedMemory = IntPtr.Zero;
     }
 }
예제 #2
0
        private void FreeMemory()
        {
            IntPtr ptr = Interlocked.Exchange(ref _pointer, IntPtr.Zero);

            // If pointer is null, the memory was already freed or never allocated.
            if (ptr != IntPtr.Zero)
            {
                if (_usesSharedMemory)
                {
                    MemoryManagement.UnmapSharedMemory(ptr);

                    if (_sharedMemory != IntPtr.Zero && !_isMirror)
                    {
                        MemoryManagement.DestroySharedMemory(_sharedMemory);
                        _sharedMemory = IntPtr.Zero;
                    }
                }
                else
                {
                    MemoryManagement.Free(ptr);
                }
            }
        }