Class PooledBufferWriter
An IBufferWriter<T> backed by an array rented from ArrayPool<T>. Either hand the written bytes off via DetachPayload() or release them via Dispose() — never both.
public sealed class PooledBufferWriter : IBufferWriter<byte>, IDisposable
- Inheritance
-
PooledBufferWriter
- Implements
- Inherited Members
Constructors
PooledBufferWriter(int)
public PooledBufferWriter(int initialCapacity = 256)
Parameters
initialCapacityint
Properties
WrittenCount
The number of bytes written so far.
public int WrittenCount { get; }
Property Value
WrittenMemory
The bytes written so far.
public ReadOnlyMemory<byte> WrittenMemory { get; }
Property Value
Methods
Advance(int)
Notifies the IBufferWriter<T> that count data items were written to the output Span<T> or Memory<T>.
public void Advance(int count)
Parameters
DetachPayload()
Hands the rented array and written length to a new Payload and relinquishes ownership. The writer must not be used afterward.
public Payload DetachPayload()
Returns
Dispose()
Returns the rented array to the pool. A no-op after DetachPayload().
public void Dispose()
GetMemory(int)
Returns a Memory<T> to write to that is at least the requested size (specified by sizeHint).
public Memory<byte> GetMemory(int sizeHint = 0)
Parameters
Returns
- Memory<byte>
A Memory<T> of at least the size
sizeHint. IfsizeHintis 0, returns a non-empty buffer.
Exceptions
- OutOfMemoryException
The requested buffer size is not available.
GetSpan(int)
Returns a Span<T> to write to that is at least the requested size (specified by sizeHint).
public Span<byte> GetSpan(int sizeHint = 0)