Class PoolingBufferWriter<T>
Represents memory writer that uses pooled memory.
Inherited Members
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public sealed class PoolingBufferWriter<T> : BufferWriter<T>, IBufferWriter<T>, ISupplier<ReadOnlyMemory<T>>, IFunctional<Func<ReadOnlyMemory<T>>>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IGrowableBuffer<T>, IReadOnlySpanConsumer<T>, ISupplier<ReadOnlyMemory<T>, CancellationToken, ValueTask>, IFunctional<Func<ReadOnlyMemory<T>, CancellationToken, ValueTask>>, IResettable, IMemoryOwner<T>, IDisposable
Type Parameters
| Name | Description |
|---|---|
| T | The data type that can be written. |
Remarks
Initializes a new writer with the default initial capacity.
Constructors
| Edit this page View SourcePoolingBufferWriter(MemoryAllocator<T>?)
Represents memory writer that uses pooled memory.
Declaration
public PoolingBufferWriter(MemoryAllocator<T>? allocator = null)
Parameters
| Type | Name | Description |
|---|---|---|
| MemoryAllocator<T> | allocator | The allocator of internal buffer. |
Remarks
Initializes a new writer with the default initial capacity.
Properties
| Edit this page View SourceCapacity
Gets or sets the total amount of space within the underlying memory.
Declaration
public override int Capacity { get; init; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
WrittenMemory
Gets the data written to the underlying buffer so far.
Declaration
public override ReadOnlyMemory<T> WrittenMemory { get; }
Property Value
| Type | Description |
|---|---|
| ReadOnlyMemory<T> |
Overrides
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | This writer has been disposed. |
Methods
| Edit this page View SourceClear(bool)
Clears the data written to the underlying memory.
Declaration
public override void Clear(bool reuseBuffer = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | reuseBuffer | true to reuse the internal buffer; false to destroy the internal buffer. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | This writer has been disposed. |
DetachBuffer()
Transfers ownership of the written memory from this writer to the caller.
Declaration
public override MemoryOwner<T> DetachBuffer()
Returns
| Type | Description |
|---|---|
| MemoryOwner<T> | The object representing all written content. |
Overrides
Remarks
The caller is responsible for the lifetime of the returned buffer. The current state of this writer will be reset.
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | This writer has been disposed. |
Dispose(bool)
Releases managed and unmanaged resources associated with this object.
Declaration
protected override void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing | true if called from Dispose(); false if called from finalizer ~Disposable(). |
Overrides
| Edit this page View SourceGetMemory(int)
Returns the memory to write to that is at least the requested size.
Declaration
public override Memory<T> GetMemory(int sizeHint = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| int | sizeHint | The minimum length of the returned memory. |
Returns
| Type | Description |
|---|---|
| Memory<T> | The memory block of at least the size |
Overrides
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | The requested buffer size is not available. |
| ObjectDisposedException | This writer has been disposed. |
GetSpan(int)
Returns the memory to write to that is at least the requested size.
Declaration
public override Span<T> GetSpan(int sizeHint = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| int | sizeHint | The minimum length of the returned memory. |
Returns
| Type | Description |
|---|---|
| Span<T> | The memory block of at least the size |
Overrides
Exceptions
| Type | Condition |
|---|---|
| OutOfMemoryException | The requested buffer size is not available. |
| ObjectDisposedException | This writer has been disposed. |