Пример #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);
            }
        }
Пример #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();
                }
            }
        }
Пример #3
0
 public static void ThrowInvalidOperationException_BlockIsBackedByDisposedSlab(DiagnosticPoolBlock block)
 {
     throw new InvalidOperationException(GenerateMessage("Block is backed by disposed slab", block));
 }
Пример #4
0
 public static void ThrowInvalidOperationException_BlockReturnedToDisposedPool(DiagnosticPoolBlock block)
 {
     throw new InvalidOperationException(GenerateMessage("Block is being returned to disposed pool", block));
 }
Пример #5
0
 public static void ThrowInvalidOperationException_BlockDoubleDispose(DiagnosticPoolBlock block)
 {
     throw new InvalidOperationException("Block is being disposed twice");
 }
Пример #6
0
 public static void ThrowInvalidOperationException_ReturningPinnedBlock(DiagnosticPoolBlock block)
 {
     throw new InvalidOperationException(GenerateMessage("Disposing pinned block", block));
 }
Пример #7
0
 public static void ThrowInvalidOperationException_PinCountZero(DiagnosticPoolBlock block)
 {
     throw new InvalidOperationException(GenerateMessage("Can't unpin, pin count is zero", block));
 }