public override MemoryHandle Pin(int byteOffset = 0) { try { lock (_syncObj) { if (_isDisposed) { MemoryPoolThrowHelper.ThrowObjectDisposedException(MemoryPoolThrowHelper.ExceptionArgument.MemoryPoolBlock); } if (_pool.IsDisposed) { MemoryPoolThrowHelper.ThrowInvalidOperationException_BlockIsBackedByDisposedSlab(this); } if (byteOffset < 0 || byteOffset > _memory.Length) { MemoryPoolThrowHelper.ThrowArgumentOutOfRangeException(_memory.Length, byteOffset); } _pinCount++; _memoryHandle = _memoryHandle ?? _memory.Pin(); unsafe { return(new MemoryHandle(((IntPtr)_memoryHandle.Value.Pointer + byteOffset).ToPointer(), default, this));
public override Span <byte> GetSpan() { try { lock (_syncObj) { if (_isDisposed) { MemoryPoolThrowHelper.ThrowObjectDisposedException(MemoryPoolThrowHelper.ExceptionArgument.MemoryPoolBlock); } if (_pool.IsDisposed) { MemoryPoolThrowHelper.ThrowInvalidOperationException_BlockIsBackedByDisposedSlab(this); } return(_memory.Span); } } catch (Exception exception) { _pool.ReportException(exception); throw; } }