Struct MemoryPoolToken<T>
A lightweight container for an underlying MemoryPool<T> node.
public readonly struct MemoryPoolToken<T> : IDisposable
Type Parameters
T
Element type.
- Implements
- Inherited Members
- Extension Methods
Properties
Clear
Specifies whether or not the underlying buffer will be additionally cleared during this token's disposal.
public bool Clear { get; }
Property Value
Empty
An empty sequence.
public static MemoryPoolToken<T> Empty { get; }
Property Value
Owner
MemoryPool<T> instance that owns this token.
public MemoryPool<T>? Owner { get; }
Property Value
- MemoryPool<T>
Methods
AsMemory()
Creates a new Memory<T> instance from the underlying buffer of this token.
[Pure]
public Memory<T> AsMemory()
Returns
Remarks
Returns an Empty instance for disposed tokens.
AsSpan()
Creates a new Span<T> instance from the underlying buffer of this token.
[Pure]
public Span<T> AsSpan()
Returns
Remarks
Returns an Empty instance for disposed tokens.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Remarks
Frees the underlying node and returns it to the pool.
EnableClearing(bool)
Creates a new MemoryPoolToken<T> from this token with a new Clear value.
[Pure]
public MemoryPoolToken<T> EnableClearing(bool enabled = true)
Parameters
Returns
- MemoryPoolToken<T>
New MemoryPoolToken<T> instance.
SetLength(int)
Resizes the underlying buffer. Length change will invalidate exposed underlying buffer's Memory<T> or Span<T> instances.
public void SetLength(int length)
Parameters
length
intNew underlying buffer length.
Remarks
When new length
is less than the current length, then elements at the end of the buffer will be discarded.
Additionally, the Clear value will determine whether or not discarded elements will be cleared.
Exceptions
- ArgumentOutOfRangeException
When
length
is less than or equal to 0.
ToString()
Returns a string representation of this MemoryPoolToken<T> instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
TryGetInfo()
Returns a MemoryPool<T>.ReportInfo.Node instance that represents this token, if node exists.
[Pure]
public MemoryPool<T>.ReportInfo.Node? TryGetInfo()
Returns
- MemoryPool<T>.ReportInfo.Node?
New MemoryPool<T>.ReportInfo.Node instance or null, if node does not exist.