DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="3.2.1" />

 SparseBufferWriter<T>

Represents builder of the sparse memory buffer.

Represents enumerator over memory segments.

public bool IsSingleSegment { get; }

Gets a value indicating that this buffer consists of a single segment.

public long WrittenCount { get; }

Gets the number of written elements.

public SparseBufferWriter(int chunkSize, SparseBufferGrowth growth = 0, MemoryAllocator<T> allocator = null)

Initializes a new builder with the specified size of memory block.

Initializes a new builder with automatically selected chunk size.

Initializes a new builder which uses Shared as a default allocator of buffers.

public void Clear()

Clears internal buffers so this builder can be reused.

public void CopyTo<TConsumer>(TConsumer consumer) where TConsumer : IReadOnlySpanConsumer<T>

Passes the contents of this builder to the consumer.

public void CopyTo<TArg>(ReadOnlySpanAction<T, TArg> writer, TArg arg)

Passes the contents of this builder to the callback.

public int CopyTo(Span<T> output)

Copies the contents of this builder to the specified memory block.

Gets enumerator over memory segments.

public bool TryGetWrittenContent(out ReadOnlyMemory segment)

Attempts to get the underlying buffer if it is presented by a single segment.

public void Write(ReadOnlySpan<T> input)

Writes the block of memory to this builder.

public void Write(ReadOnlyMemory<T> input, bool copyMemory = true)

Writes the block of memory to this builder.

public void Write(ref ReadOnlySequence sequence, bool copyMemory = true)

Writes a sequence of memory blocks to this builder.