예제 #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));
 }