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