Represents builder of the sparse memory buffer.
InheritanceSparseBufferWriter<T>
Namespace: DotNext.Buffers Assembly: DotNext.dll Syntaxpublic class SparseBufferWriter<T> : Disposable, IGrowableBuffer<T>, IReadOnlySpanConsumer<T>, ISupplier<ReadOnlyMemory<T>, CancellationToken, ValueTask>, IFunctional<Func<ReadOnlyMemory<T>, CancellationToken, ValueTask>>, IDisposable, IResettable, ISupplier<ReadOnlySequence<T>>, IFunctional<Func<ReadOnlySequence<T>>>, IEnumerable<ReadOnlyMemory<T>>, IEnumerable, IBufferWriter<T>
Type Parameters Name Description T
The type of the elements in the memory.
Constructors | Edit this page View Source SparseBufferWriter()Initializes a new builder which uses Shared as a default allocator of buffers.
Declarationpublic SparseBufferWriter()
| Edit this page View Source SparseBufferWriter(MemoryPool<T>)
Initializes a new builder with automatically selected chunk size.
Declarationpublic SparseBufferWriter(MemoryPool<T> pool)
Parameters Type Name Description MemoryPool<T> pool
Memory pool used to allocate memory chunks.
| Edit this page View Source SparseBufferWriter(int, SparseBufferGrowth, MemoryAllocator<T>?)Initializes a new builder with the specified size of memory block.
Declarationpublic SparseBufferWriter(int chunkSize, SparseBufferGrowth growth = SparseBufferGrowth.None, MemoryAllocator<T>? allocator = null)
Parameters Type Name Description int chunkSize
The size of the memory block representing single segment within sequence.
SparseBufferGrowth growthSpecifies how the memory should be allocated for each subsequent chunk in this buffer.
MemoryAllocator<T> allocatorThe allocator used to rent the segments.
Exceptions Properties | Edit this page View Source EndGets the current write position within the buffer.
Declarationpublic SequencePosition End { get; }
Property Value See Also | Edit this page View Source IsSingleSegment
Gets a value indicating that this buffer consists of a single segment.
Declarationpublic bool IsSingleSegment { get; }
Property Value | Edit this page View Source Start
Gets the position of the first chunk of data within the buffer.
Declarationpublic SequencePosition Start { get; }
Property Value | Edit this page View Source WrittenCount
Gets the number of written elements.
Declarationpublic long WrittenCount { get; }
Property Value Exceptions Methods | Edit this page View Source Add(T)
Adds a single item to the buffer.
Declaration Parameters Type Name Description T itemThe item to add.
Exceptions | Edit this page View Source Clear()Clears internal buffers so this builder can be reused.
Declaration Exceptions | Edit this page View Source CopyTo(Span<T>)Copies the contents of this builder to the specified memory block.
Declarationpublic int CopyTo(Span<T> output)
Parameters Type Name Description Span<T> output
The memory block to be modified.
Returns Type Description intThe actual number of copied elements.
Exceptions | Edit this page View Source CopyTo(scoped Span<T>, scoped ref SequencePosition)Copies the elements from this buffer to the destination location, starting at the specified position, and advances the position.
Declarationpublic int CopyTo(scoped Span<T> output, scoped ref SequencePosition position)
Parameters Type Name Description Span<T> output
The destination block of memory.
SequencePosition positionThe position within this buffer.
Returns Type Description intThe number of copied elements.
Exceptions | Edit this page View Source CopyTo<TArg>(ReadOnlySpanAction<T, TArg>, TArg)Passes the contents of this builder to the callback.
Declarationpublic void CopyTo<TArg>(ReadOnlySpanAction<T, TArg> writer, TArg arg)
Parameters Type Name Description ReadOnlySpanAction<T, TArg> writer
The callback used to accept memory segments representing the contents of this builder.
TArg argThe argument to be passed to the callback.
Type Parameters Name Description TArgThe type of the argument to tbe passed to the callback.
Exceptions | Edit this page View Source CopyTo<TConsumer>(TConsumer)Passes the contents of this builder to the consumer.
Declarationpublic void CopyTo<TConsumer>(TConsumer consumer) where TConsumer : IReadOnlySpanConsumer<T>
Parameters Type Name Description TConsumer consumer
The consumer of this buffer.
Type Parameters Name Description TConsumerThe type of the consumer.
Exceptions | Edit this page View Source CopyTo<TConsumer>(TConsumer, SequencePosition)Passes the elements from this buffer to the specified consumer, starting at the specified position.
Declarationpublic void CopyTo<TConsumer>(TConsumer consumer, SequencePosition start) where TConsumer : IReadOnlySpanConsumer<T>
Parameters Type Name Description TConsumer consumer
The consumer to be called multiple times to process the chunk of data.
SequencePosition startThe start position within this buffer.
Type Parameters Name Description TConsumerThe type of the consumer.
Exceptions | Edit this page View Source CopyTo<TConsumer>(TConsumer, scoped ref SequencePosition, long)Passes the elements from this buffer to the specified consumer, starting at the specified position, and advances the position.
Declarationpublic long CopyTo<TConsumer>(TConsumer consumer, scoped ref SequencePosition position, long count) where TConsumer : IReadOnlySpanConsumer<T>
Parameters Type Name Description TConsumer consumer
The consumer to be called multiple times to process the chunk of data.
SequencePosition positionThe position within this buffer.
long countThe number of elements to read.
Returns Type Description longThe actual number of copied elements.
Type Parameters Name Description TConsumerThe type of the consumer.
Exceptions | Edit this page View Source Dispose(bool)Releases managed and unmanaged resources associated with this object.
Declarationprotected override void Dispose(bool disposing)
Parameters Overrides | Edit this page View Source GetEnumerator()
Gets enumerator over memory segments.
Declarationpublic SparseBufferWriter<T>.Enumerator GetEnumerator()
Returns Exceptions | Edit this page View Source GetPosition(long, SequencePosition)
Returns a position at an offset from the specified position within this buffer.
Declarationpublic SequencePosition GetPosition(long offset, SequencePosition origin = default)
Parameters Type Name Description long offset
The offset from the specified origin
position.
A position from which to initiate the offset.
Returns Exceptions | Edit this page View Source Read(ref SequencePosition, long)Reads the data from this buffer, and advances the position to the specified number of elements.
Declarationpublic ReadOnlySequence<T> Read(ref SequencePosition position, long count)
Parameters Type Name Description SequencePosition position
The start position within this buffer.
long countThe number of elements to read.
Returns Type Description ReadOnlySequence<T>A collection of memory chunks containing the requested number of elements.
Exceptions | Edit this page View Source ToString()Returns the textual representation of this buffer.
Declarationpublic override string ToString()
Returns Type Description string
The textual representation of this buffer.
Overrides | Edit this page View Source TryGetWrittenContent(out ReadOnlyMemory<T>)Attempts to get the underlying buffer if it is presented by a single segment.
Declarationpublic bool TryGetWrittenContent(out ReadOnlyMemory<T> segment)
Parameters Type Name Description ReadOnlyMemory<T> segment
The single segment representing written content.
Returns Type Description booltrue if this buffer is represented by a single segment; otherwise, false.
Exceptions | Edit this page View Source Write(in ReadOnlySequence<T>, bool)Writes a sequence of memory blocks to this builder.
Declarationpublic void Write(in ReadOnlySequence<T> sequence, bool copyMemory = true)
Parameters Type Name Description ReadOnlySequence<T> sequence
A sequence of memory blocks.
bool copyMemorytrue to copy the content of the input buffer; false to import memory blocks.
Exceptions | Edit this page View Source Write(ReadOnlyMemory<T>, bool)Writes the block of memory to this builder.
Declarationpublic void Write(ReadOnlyMemory<T> input, bool copyMemory = true)
Parameters Type Name Description ReadOnlyMemory<T> input
The memory block to be written to this builder.
bool copyMemorytrue to copy the content of the input buffer; false to import the memory block.
Exceptions | Edit this page View Source Write(ReadOnlySpan<T>)Writes the block of memory to this builder.
Declarationpublic void Write(ReadOnlySpan<T> input)
Parameters Type Name Description ReadOnlySpan<T> input
The memory block to be written to this builder.
Exceptions Implements Extension Methods See AlsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4