Show / Hide Table of Contents

Struct MemoryOwner<T>

Represents unified representation of the memory rented using various types of memory pools.

Implements
IMemoryOwner<T>
IDisposable
ISupplier<Memory<T>>
ISupplier<ReadOnlyMemory<T>>
IFunctional
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
object.GetType()
object.Equals(object, object)
object.ReferenceEquals(object, object)
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public struct MemoryOwner<T> : IMemoryOwner<T>, IDisposable, ISupplier<Memory<T>>, ISupplier<ReadOnlyMemory<T>>, IFunctional
Type Parameters
Name Description
T

The type of the items in the memory pool.

Constructors

View Source

MemoryOwner(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.

View Source

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 -1 to rent default amount of memory.

View Source

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.

View Source

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.

View Source

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.

View Source

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

length is less than 0 or greater than the length of array.

Properties

View Source

DataRef

Gets managed pointer to the first element in the rented memory block.

Declaration
public readonly ref T DataRef { get; }
Property Value
Type Description
T
View Source

IsEmpty

Determines whether this memory is empty.

Declaration
public readonly bool IsEmpty { get; }
Property Value
Type Description
bool
View Source

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

index is invalid.

View Source

Length

Gets numbers of elements in the rented memory block.

Declaration
public readonly int Length { get; }
Property Value
Type Description
int
View Source

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.

View Source

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

View Source

Dispose()

Releases rented memory.

Declaration
public void Dispose()
View Source

ToString()

Declaration
public override readonly string ToString()
Returns
Type Description
string
Overrides
ValueType.ToString()
View Source

TryResize(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

This method always return true if newLength is less than or equal to Length.

Exceptions
Type Condition
ArgumentOutOfRangeException

newLength is less than zero.

Implements

IMemoryOwner<T>
IDisposable
ISupplier<TResult>
ISupplier<TResult>
IFunctional

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)
Memory.Resize<T>(ref MemoryOwner<T>, int, MemoryAllocator<T>)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾