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>>
IFunctional<Func<Memory<T>>>
ISupplier<ReadOnlyMemory<T>>
IFunctional<Func<ReadOnlyMemory<T>>>
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
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 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.

| Edit this page 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.

| Edit this page 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.

| Edit this page 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.

| Edit this page 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.

| Edit this page 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

| Edit this page View Source

IsEmpty

Determines whether this memory is empty.

Declaration
public readonly bool IsEmpty { get; }
Property Value
Type Description
bool
| Edit this page 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.

| Edit this page View Source

Length

Gets numbers of elements in the rented memory block.

Declaration
public readonly int Length { get; }
Property Value
Type Description
int
| Edit this page 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.

| Edit this page 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

| Edit this page View Source

Dispose()

Releases rented memory.

Declaration
public void Dispose()
| Edit this page View Source

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
ValueType.ToString()
| Edit this page 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>
IFunctional<TDelegate>
ISupplier<TResult>
IFunctional<TDelegate>

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
Memory.Resize<T>(ref MemoryOwner<T>, int, MemoryAllocator<T>?)
Collection.ToAsyncEnumerator<TEnumerator, T>(TEnumerator, CancellationToken)
Collection.ToClassicEnumerator<TEnumerator, T>(TEnumerator)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
ExpressionBuilder.Const<T>(T)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾