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