Class SparseBufferWriter<T>
Represents builder of the sparse memory buffer.
Implements
Inherited Members
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public class SparseBufferWriter<T> : Disposable, IEnumerable<ReadOnlyMemory<T>>, IEnumerable, IGrowableBuffer<T>, IDisposable, IConvertible<ReadOnlySequence<T>>, IBufferWriter<T>
Type Parameters
Name | Description |
---|---|
T | The type of the elements in the memory. |
Remarks
All members of IBufferWriter<T> are explicitly implemented because their usage can produce holes in the sparse buffer. To avoid holes, use public members only.
Constructors
| Improve this Doc View SourceSparseBufferWriter()
Initializes a new builder which uses Shared as a default allocator of buffers.
Declaration
public SparseBufferWriter()
SparseBufferWriter(MemoryPool<T>)
Initializes a new builder with automatically selected chunk size.
Declaration
public SparseBufferWriter(MemoryPool<T> pool)
Parameters
Type | Name | Description |
---|---|---|
MemoryPool<T> | pool | Memory pool used to allocate memory chunks. |
SparseBufferWriter(Int32, MemoryAllocator<T>)
Initializes a new builder with the specified size of memory block.
Declaration
public SparseBufferWriter(int chunkSize, MemoryAllocator<T> allocator = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | chunkSize | The size of the memory block representing single segment within sequence. |
MemoryAllocator<T> | allocator | The allocator used to rent the segments. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
Properties
| Improve this Doc View SourceWrittenCount
Gets the number of written elements.
Declaration
public long WrittenCount { get; }
Property Value
Type | Description |
---|---|
Int64 |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The builder has been disposed. |
Methods
| Improve this Doc View SourceClear()
Clears internal buffers so this builder can be reused.
Declaration
public void Clear()
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The builder has been disposed. |
CopyTo(Span<T>)
Copies the contents of this builder to the specified memory block.
Declaration
public int CopyTo(Span<T> output)
Parameters
Type | Name | Description |
---|---|---|
Span<T> | output | The memory block to be modified. |
Returns
Type | Description |
---|---|
Int32 | The actual number of copied elements. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The builder has been disposed. |
CopyTo<TArg>(ReadOnlySpanAction<T, TArg>, TArg)
Passes the contents of this builder to the callback.
Declaration
public 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 | arg | The argument to be passed to the callback. |
Type Parameters
Name | Description |
---|---|
TArg | The type of the argument to tbe passed to the callback. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The builder has been disposed. |
Dispose(Boolean)
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing |
Overrides
| Improve this Doc View SourceGetEnumerator()
Gets enumerator over memory segments.
Declaration
public SparseBufferWriter<T>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
SparseBufferWriter.Enumerator<> | The enumerator over memory segments. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The builder has been disposed. |
Write(ReadOnlySequence<T>, Boolean)
Writes a sequence of memory blocks to this builder.
Declaration
public void Write(in ReadOnlySequence<T> sequence, bool copyMemory = true)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySequence<T> | sequence | A sequence of memory blocks. |
Boolean | copyMemory | true to copy the content of the input buffer; false to import memory blocks. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The builder has been disposed. |
Write(ReadOnlyMemory<T>, Boolean)
Writes the block of memory to this builder.
Declaration
public void Write(ReadOnlyMemory<T> input, bool copyMemory = true)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlyMemory<T> | input | The memory block to be written to this builder. |
Boolean | copyMemory | true to copy the content of the input buffer; false to import the memory block. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The builder has been disposed. |
Write(ReadOnlySpan<T>)
Writes the block of memory to this builder.
Declaration
public void Write(ReadOnlySpan<T> input)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<T> | input | The memory block to be written to this builder. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The builder has been disposed. |
Explicit Interface Implementations
| Improve this Doc View SourceIConvertible<ReadOnlySequence<T>>.Convert()
Declaration
ReadOnlySequence<T> IConvertible<ReadOnlySequence<T>>.Convert()
Returns
Type | Description |
---|---|
ReadOnlySequence<T> |
IBufferWriter<T>.Advance(Int32)
Declaration
void IBufferWriter<T>.Advance(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count |
IBufferWriter<T>.GetMemory(Int32)
Declaration
Memory<T> IBufferWriter<T>.GetMemory(int sizeHint)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sizeHint |
Returns
Type | Description |
---|---|
Memory<T> |
IBufferWriter<T>.GetSpan(Int32)
Declaration
Span<T> IBufferWriter<T>.GetSpan(int sizeHint)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sizeHint |
Returns
Type | Description |
---|---|
Span<T> |
IEnumerable<ReadOnlyMemory<T>>.GetEnumerator()
Declaration
IEnumerator<ReadOnlyMemory<T>> IEnumerable<ReadOnlyMemory<T>>.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<ReadOnlyMemory<T>> |
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator |