SlabSliceWriter

Namespace: SnowBank.Buffers · class

Implements: IBufferWriter<byte>, ISliceBufferWriter, ISpanEncodable

Buffer writer that writes all data into a slabs allocated from a pool (or the heap)

Remarks

This buffer will allocate new slabs of memory as needed, and keep them alive until it is disposed or cleared.

Constructors

SlabSliceWriter

SlabSliceWriter()

Constructs a SlabSliceWriter using the default slab and spill sizes

SlabSliceWriter(int initialSize)

Constructs a SlabSliceWriter using a custom initial slab and spill sizes

SlabSliceWriter(int initialSize, int spillSize)

Constructs a SlabSliceWriter, in which data can be written to, with an initial capacity specified.

  • initialSize — The initial capacity with which to initialize the underlying buffer.
  • spillSize — The maximum required size that will be served from the pool. Larger buffer size will be allocated from the heap

Properties

FreeCapacity

int FreeCapacity { get; }

Returns the amount of space available that can still be written into without forcing the underlying buffer to grow.

MaxSlabSize

int MaxSlabSize { get; }

Maximum size of slabs allocated from the pool. Slabs with a size greater than this value will be allocated on the heap instead.

WrittenCount

long WrittenCount { get; }

Returns the amount of data written to the underlying buffer so far.

Methods

Advance

void Advance(int count)

Notifies the ISliceBufferWriter that count data items were written to the output Slice.

  • count — The number of data items written to the Slice.

Allocate

ArraySegment<byte> Allocate(int size)

Returns a ArraySegment to write to that is exactly the requested size (specified by size) and advance the cursor.

  • size — The exact length of the returned Slice. If 0, a non-empty buffer is returned.

Returns: A ArraySegment of at exactly the size requested.

Clear

void Clear()

Clears the data written to the underlying buffers.

You must clear the before trying to re-use it.

GetMemory

Memory<byte> GetMemory(int sizeHint = 0)

Returns a Memory to write to that is at least the requested length (specified by sizeHint). If no sizeHint is provided (or it's equal to 0), some non-empty buffer is returned.

This will never return an empty .

GetSlice

ArraySegment<byte> GetSlice(int sizeHint = 0)

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

  • sizeHint — The minimum length of the returned Slice. If 0, a non-empty buffer is returned.

Returns: A ArraySegment of at least the size sizeHint. If sizeHint is 0, returns a non-empty buffer.

GetSpan

Span<byte> GetSpan(int sizeHint = 0)

Returns a Span to write to that is at least the requested length (specified by sizeHint). If no sizeHint is provided (or it's equal to 0), some non-empty buffer is returned.

This will never return an empty .