Class MemoryWriter<T>
Represents memory-backed output sink which T
data can be written.
Implements
Inherited Members
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public abstract class MemoryWriter<T> : Disposable, IBufferWriter<T>, IConvertible<ReadOnlyMemory<T>>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IGrowableBuffer<T>, IDisposable
Type Parameters
Name | Description |
---|---|
T | The data type that can be written. |
Properties
| Improve this Doc View SourceAllocationCounter
Sets the counter used to report allocation of internal buffer.
Declaration
public EventCounter AllocationCounter { set; }
Property Value
Type | Description |
---|---|
EventCounter |
BufferSizeCallback
Sets the callback used internally to report actual size of allocated buffer.
Declaration
public Action<int> BufferSizeCallback { set; }
Property Value
Type | Description |
---|---|
Action<Int32> |
Capacity
Gets the total amount of space within the underlying memory.
Declaration
public abstract int Capacity { get; }
Property Value
Type | Description |
---|---|
Int32 |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This writer has been disposed. |
FreeCapacity
Gets the amount of space available that can still be written into without forcing the underlying buffer to grow.
Declaration
public int FreeCapacity { get; }
Property Value
Type | Description |
---|---|
Int32 |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This writer has been disposed. |
Item[Int32]
Gets the element at the specified index.
Declaration
public T this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index of the element to retrieve. |
Property Value
Type | Description |
---|---|
T | The element at the specified index. |
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException |
|
ObjectDisposedException | This writer has been disposed. |
WrittenCount
Gets the amount of data written to the underlying memory so far.
Declaration
public int WrittenCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This writer has been disposed. |
WrittenMemory
Gets the data written to the underlying buffer so far.
Declaration
public abstract ReadOnlyMemory<T> WrittenMemory { get; }
Property Value
Type | Description |
---|---|
ReadOnlyMemory<T> |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This writer has been disposed. |
Methods
| Improve this Doc View SourceAdd(T)
Writes single element.
Declaration
public void Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element to write. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This writer has been disposed. |
AddAll(ICollection<T>)
Writes multiple elements.
Declaration
public void AddAll(ICollection<T> items)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | items | The collection of elements to be copied. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This writer has been disposed. |
Advance(Int32)
Notifies this writer that count
of data items were written.
Declaration
public void Advance(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | The number of data items written to the underlying buffer. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
InvalidOperationException | Attempts to advance past the end of the underlying buffer. |
ObjectDisposedException | This writer has been disposed. |
Clear()
Clears the data written to the underlying memory.
Declaration
public virtual void Clear()
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This writer has been disposed. |
Clear(Boolean)
Clears the data written to the underlying memory.
Declaration
public abstract void Clear(bool reuseBuffer)
Parameters
Type | Name | Description |
---|---|---|
Boolean | reuseBuffer | true to reuse the internal buffer; false to destroy the internal buffer. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This writer 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 all written elements.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<T> | The enumerator over all written elements. |
GetMemory(Int32)
Returns the memory to write to that is at least the requested size.
Declaration
public abstract Memory<T> GetMemory(int sizeHint = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sizeHint | The minimum length of the returned memory. |
Returns
Type | Description |
---|---|
Memory<T> | The memory block of at least the size |
Exceptions
Type | Condition |
---|---|
OutOfMemoryException | The requested buffer size is not available. |
ObjectDisposedException | This writer has been disposed. |
GetSpan(Int32)
Returns the memory to write to that is at least the requested size.
Declaration
public virtual Span<T> GetSpan(int sizeHint = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sizeHint | The minimum length of the returned memory. |
Returns
Type | Description |
---|---|
Span<T> | The memory block of at least the size |
Exceptions
Type | Condition |
---|---|
OutOfMemoryException | The requested buffer size is not available. |
ObjectDisposedException | This writer has been disposed. |
Explicit Interface Implementations
| Improve this Doc View SourceIGrowableBuffer<T>.CopyTo(Span<T>)
Declaration
int IGrowableBuffer<T>.CopyTo(Span<T> output)
Parameters
Type | Name | Description |
---|---|---|
Span<T> | output |
Returns
Type | Description |
---|---|
Int32 |
IGrowableBuffer<T>.CopyTo<TArg>(ReadOnlySpanAction<T, TArg>, TArg)
Declaration
void IGrowableBuffer<T>.CopyTo<TState>(ReadOnlySpanAction<T, TState> callback, TState state)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpanAction<T, TState> | callback | |
TState | state |
Type Parameters
Name | Description |
---|---|
TState |
IGrowableBuffer<T>.Write(ReadOnlySpan<T>)
Declaration
void IGrowableBuffer<T>.Write(ReadOnlySpan<T> input)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<T> | input |
IGrowableBuffer<T>.WrittenCount
Declaration
long IGrowableBuffer<T>.WrittenCount { get; }
Returns
Type | Description |
---|---|
Int64 |
IConvertible<ReadOnlyMemory<T>>.Convert()
Declaration
ReadOnlyMemory<T> IConvertible<ReadOnlyMemory<T>>.Convert()
Returns
Type | Description |
---|---|
ReadOnlyMemory<T> |
IReadOnlyCollection<T>.Count
Declaration
int IReadOnlyCollection<T>.Count { get; }
Returns
Type | Description |
---|---|
Int32 |
IReadOnlyList<T>.Item[Int32]
Declaration
T IReadOnlyList<T>.this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |
Returns
Type | Description |
---|---|
T |
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator |