Exemplo n.º 1
0
        public override IMemoryOwner <byte> Rent(int size = AnySize)
        {
            lock (_syncObj)
            {
                if (IsDisposed)
                {
                    MemoryPoolThrowHelper.ThrowObjectDisposedException(MemoryPoolThrowHelper.ExceptionArgument.MemoryPool);
                }

                var diagnosticPoolBlock = new DiagnosticPoolBlock(this, _pool.Rent(size));
                if (_rentTracking)
                {
                    diagnosticPoolBlock.Track();
                }
                _totalBlocks++;
                _blocks.Add(diagnosticPoolBlock);
                return(diagnosticPoolBlock);
            }
        }
Exemplo n.º 2
0
        internal void Return(DiagnosticPoolBlock block)
        {
            bool returnedAllBlocks;

            lock (_syncObj)
            {
                _blocks.Remove(block);
                returnedAllBlocks = _blocks.Count == 0;
            }

            if (IsDisposed)
            {
                if (!_allowLateReturn)
                {
                    MemoryPoolThrowHelper.ThrowInvalidOperationException_BlockReturnedToDisposedPool(block);
                }

                if (returnedAllBlocks)
                {
                    SetAllBlocksReturned();
                }
            }
        }
Exemplo n.º 3
0
 public static void ThrowInvalidOperationException_BlockIsBackedByDisposedSlab(DiagnosticPoolBlock block)
 {
     throw new InvalidOperationException(GenerateMessage("Block is backed by disposed slab", block));
 }
Exemplo n.º 4
0
 public static void ThrowInvalidOperationException_BlockReturnedToDisposedPool(DiagnosticPoolBlock block)
 {
     throw new InvalidOperationException(GenerateMessage("Block is being returned to disposed pool", block));
 }
Exemplo n.º 5
0
 public static void ThrowInvalidOperationException_BlockDoubleDispose(DiagnosticPoolBlock block)
 {
     throw new InvalidOperationException("Block is being disposed twice");
 }
Exemplo n.º 6
0
 public static void ThrowInvalidOperationException_ReturningPinnedBlock(DiagnosticPoolBlock block)
 {
     throw new InvalidOperationException(GenerateMessage("Disposing pinned block", block));
 }
Exemplo n.º 7
0
 public static void ThrowInvalidOperationException_PinCountZero(DiagnosticPoolBlock block)
 {
     throw new InvalidOperationException(GenerateMessage("Can't unpin, pin count is zero", block));
 }