Skip to content

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>, IDisposable

objectPooledBufferWriter

IBufferWriter<byte>, IDisposable

object.Equals(object), object.Equals(object, object), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object, object), object.ToString()

public PooledBufferWriter(int initialCapacity = 256)

initialCapacity int

The number of bytes written so far.

public int WrittenCount { get; }

int

The bytes written so far.

public ReadOnlyMemory<byte> WrittenMemory { get; }

ReadOnlyMemory<byte>

Notifies the System.Buffers.IBufferWriter that count data items were written to the output System.Span or System.Memory.

public void Advance(int count)

count int

The number of data items written to the System.Span or System.Memory.

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()

Payload

Returns the rented array to the pool. A no-op after DotBoxD.Services.Buffers.PooledBufferWriter.DetachPayload.

public void Dispose()

Returns a System.Memory to write to that is at least the requested size (specified by sizeHint).

public Memory<byte> GetMemory(int sizeHint = 0)

sizeHint int

The minimum length of the returned System.Memory. If 0, a non-empty buffer is returned.

Memory<byte>

A System.Memory of at least the size sizeHint. If sizeHint is 0, returns a non-empty buffer.

OutOfMemoryException

The requested buffer size is not available.

Returns a System.Span to write to that is at least the requested size (specified by sizeHint).

public Span<byte> GetSpan(int sizeHint = 0)

sizeHint int

The minimum length of the returned System.Span. If 0, a non-empty buffer is returned.

Span<byte>

A System.Span of at least the size sizeHint. If sizeHint is 0, returns a non-empty buffer.