DotNext by .NET Foundation and Contributors

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

 SparseBufferWriter<T>

Represents builder of the sparse memory buffer.

Represents enumerator over memory segments.

public SequencePosition End { get; }

Gets the current write position within the buffer.

public bool IsSingleSegment { get; }

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

public SequencePosition Start { get; }

Gets the position of the first chunk of data within the buffer.

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 Add(T item)

Adds a single item to the buffer.

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.

public int CopyTo(Span<T> output, ref SequencePosition position)

Copies the elements from this buffer to the destination location, starting at the specified position, and advances the position.

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

Passes the elements from this buffer to the specified consumer, starting at the specified position.

public long CopyTo<TConsumer>(TConsumer consumer, ref SequencePosition position, long count) where TConsumer : IReadOnlySpanConsumer<T>

Passes the elements from this buffer to the specified consumer, starting at the specified position, and advances the position.

Gets enumerator over memory segments.

public SequencePosition GetPosition(long offset, SequencePosition origin = default)

Returns a position at an offset from the specified position within this buffer.

public ReadOnlySequence<T> Read(ref SequencePosition position, long count)

Reads the data from this buffer, and advances the position to the specified number of elements.

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.