public override void Retain() { if (IsDisposed) { PipelinesThrowHelper.ThrowObjectDisposedException(nameof(MemoryPoolBlock)); } Interlocked.Increment(ref _referenceCount); }
public override Span <byte> AsSpan(int index, int length) { if (IsDisposed) { PipelinesThrowHelper.ThrowObjectDisposedException(nameof(DisposeTrackingBufferPool)); } return(_array.Slice(index, length)); }
/// <summary> /// Moves to the next <see cref="Buffer{Byte}"/> in the <see cref="ReadableBuffer"/> /// </summary> /// <returns></returns> public bool MoveNext() { var segment = _segment; if (segment == null) { return(false); } if (segment is BufferSegment bufferSegment) { var start = _startIndex; var end = bufferSegment.End; if (segment == _endSegment) { end = _endIndex; _segment = null; } else { _segment = bufferSegment.Next; if (_segment == null) { if (_endSegment != null) { ThrowEndNotSeen(); } } else { _startIndex = bufferSegment.Next.Start; } } Current = bufferSegment.Memory.Slice(start, end - start); _cursorSegment = bufferSegment; _cursorStart = start; return(true); } if (segment is byte[] array) { Current = new Memory <byte>(array, _startIndex, _endIndex - _startIndex); _cursorSegment = segment; _cursorStart = _startIndex; if (_segment != _endSegment) { ThrowEndNotSeen(); } _segment = null; return(true); } PipelinesThrowHelper.ThrowNotSupportedException(); return(default);
protected override bool TryGetArray(out ArraySegment <byte> arraySegment) { if (IsDisposed) { PipelinesThrowHelper.ThrowObjectDisposedException(nameof(DisposeTrackingBufferPool)); } arraySegment = new ArraySegment <byte>(_array); return(true); }
// In kestrel both MemoryPoolBlock and OwnedMemory end up in the same assembly so // this method access modifiers need to be `protected internal` protected override bool TryGetArray(out ArraySegment <byte> arraySegment) { if (IsDisposed) { PipelinesThrowHelper.ThrowObjectDisposedException(nameof(MemoryPoolBlock)); } arraySegment = new ArraySegment <byte>(Slab.Array, _offset, _length); return(true); }
public override OwnedMemory <byte> Rent(int size) { if (size > _blockLength) { PipelinesThrowHelper.ThrowArgumentOutOfRangeException_BufferRequestTooLarge(_blockLength); } var block = Lease(); return(block); }
public override MemoryHandle Pin() { if (IsDisposed) { PipelinesThrowHelper.ThrowObjectDisposedException(nameof(MemoryPoolBlock)); } Retain(); unsafe { return(new MemoryHandle(this, (Slab.NativePointer + _offset).ToPointer())); } }
public override MemoryHandle Pin(int byteOffset = 0) { Retain(); // checks IsDisposed if (byteOffset < 0 || byteOffset > _length) { PipelinesThrowHelper.ThrowArgumentOutOfRangeException(_length, byteOffset); } unsafe { return(new MemoryHandle(this, (Slab.NativePointer + _offset + byteOffset).ToPointer())); } }
public override bool Release() { int newRefCount = Interlocked.Decrement(ref _referenceCount); if (newRefCount < 0) { PipelinesThrowHelper.ThrowInvalidOperationException(ExceptionResource.ReferenceCountZero); } if (newRefCount == 0) { OnZeroReferences(); return(false); } return(true); }
/// <summary> /// /// </summary> public void Reset() { PipelinesThrowHelper.ThrowNotSupportedException(); }