Struct MemoryOwner<T>
Represents unified representation of the memory rented using various types of memory pools.
Implements
Inherited Members
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public struct MemoryOwner<T> : IMemoryOwner<T>, IDisposable, ISupplier<Memory<T>>, IFunctional<Func<Memory<T>>>, ISupplier<ReadOnlyMemory<T>>, IFunctional<Func<ReadOnlyMemory<T>>>
Type Parameters
Name | Description |
---|---|
T | The type of the items in the memory pool. |
Constructors
| Edit this page View SourceMemoryOwner(ArrayPool<T>, int)
Rents the array from the pool.
Declaration
public MemoryOwner(ArrayPool<T> pool, int length)
Parameters
Type | Name | Description |
---|---|---|
ArrayPool<T> | pool | The array pool. |
int | length | The length of the array. |
MemoryOwner(MemoryPool<T>, int)
Rents the memory from the pool.
Declaration
public MemoryOwner(MemoryPool<T> pool, int length = -1)
Parameters
Type | Name | Description |
---|---|---|
MemoryPool<T> | pool | The memory pool. |
int | length | The number of elements to rent; or |
MemoryOwner(Func<IMemoryOwner<T>>)
Rents the memory.
Declaration
public MemoryOwner(Func<IMemoryOwner<T>> provider)
Parameters
Type | Name | Description |
---|---|---|
Func<IMemoryOwner<T>> | provider | The memory provider. |
MemoryOwner(Func<int, IMemoryOwner<T>>, int)
Rents the memory.
Declaration
public MemoryOwner(Func<int, IMemoryOwner<T>> provider, int length)
Parameters
Type | Name | Description |
---|---|---|
Func<int, IMemoryOwner<T>> | provider | The memory provider. |
int | length | The number of elements to rent. |
MemoryOwner(T[])
Wraps the array as if it was rented.
Declaration
public MemoryOwner(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to wrap. |
MemoryOwner(T[], int)
Wraps the array as if it was rented.
Declaration
public MemoryOwner(T[] array, int length)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array to wrap. |
int | length | The length of the array. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
Properties
| Edit this page View SourceIsEmpty
Determines whether this memory is empty.
Declaration
public readonly bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool |
this[int]
Gets managed pointer to the item in the rented memory.
Declaration
public readonly ref T this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the element in memory. |
Property Value
Type | Description |
---|---|
T | The managed pointer to the item. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
Length
Gets numbers of elements in the rented memory block.
Declaration
public readonly int Length { get; }
Property Value
Type | Description |
---|---|
int |
Memory
Gets the memory belonging to this owner.
Declaration
public readonly Memory<T> Memory { get; }
Property Value
Type | Description |
---|---|
Memory<T> | The memory belonging to this owner. |
Span
Gets the span over the memory belonging to this owner.
Declaration
public readonly Span<T> Span { get; }
Property Value
Type | Description |
---|---|
Span<T> | The span over the memory belonging to this owner. |
Methods
| Edit this page View SourceDispose()
Releases rented memory.
Declaration
public void Dispose()
ToString()
Returns the fully qualified type name of this instance.
Declaration
public override readonly string ToString()
Returns
Type | Description |
---|---|
string | The fully qualified type name. |
Overrides
| Edit this page View SourceTryResize(int)
Attempts to resize this buffer without reallocation.
Declaration
public bool TryResize(int newLength)
Parameters
Type | Name | Description |
---|---|---|
int | newLength | The requested length of this buffer. |
Returns
Type | Description |
---|---|
bool | true if this buffer is resized successfully; otherwise, false. |
Remarks
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|