コード例 #1
0
        public void Return(byte *ptr, int size, NativeMemory.ThreadStats allocatingThread)
        {
            if (ptr == null)
            {
                return;
            }

            size = Bits.NextPowerOf2(size);
            Sodium.ZeroMemory(ptr, size);

            if (size > Constants.Size.Megabyte * 16)
            {
                // We don't want to pool large buffers
                NativeMemory.Free4KbAlignedMemory(ptr, size, allocatingThread);
                return;
            }

            var index = Bits.MostSignificantBit(size);

            _items[index].Push(new NativeAllocation()
            {
                Ptr = (IntPtr)ptr,
                AllocatingThread = allocatingThread,
                Size             = size
            });
        }
コード例 #2
0
 private void ReleaseUnmanagedResources()
 {
     foreach (var stack in _items)
     {
         while (stack.TryPop(out var allocation))
         {
             NativeMemory.Free4KbAlignedMemory((byte *)allocation.Ptr, allocation.Size, allocation.AllocatingThread);
         }
     }
 }
コード例 #3
0
 public void Dispose()
 {
     if (_encryptionBuffers != null) // Encryption enabled
     {
         foreach (var buffer in _encryptionBuffers)
         {
             NativeMemory.Free4KbAlignedMemory(buffer.Pointer, buffer.Size, buffer.AllocatingThread);
         }
         BeforeCommitFinalization?.Invoke(this);
     }
     OnDispose?.Invoke(this);
 }