DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.12.3" />

 MemoryOwner<T>

Represents unified representation of the memory rented using various types of memory pools.
public bool IsEmpty { get; }

Determines whether this memory is empty.

public ref T this[IntPtr index] { get; }

Gets managed pointer to the item in the rented memory.

public ref T this[int index] { get; }

Gets managed pointer to the item in the rented memory.

public int Length { get; }

Gets numbers of elements in the rented memory block.

public Memory<T> Memory { get; }

Gets the memory belonging to this owner.

public Span<T> Span { get; }

Gets the span over the memory belonging to this owner.

public MemoryOwner(ArrayPool<T> pool, int length)

Rents the array from the pool.

public MemoryOwner(MemoryPool<T> pool, int length = -1)

Rents the memory from the pool.

public MemoryOwner(Func<int, IMemoryOwner<T>> provider, int length)

Rents the memory.

public MemoryOwner(Func<IMemoryOwner<T>> provider)

Rents the memory.

public MemoryOwner(T[] array, int length)

Wraps the array as if it was rented.

public MemoryOwner(T[] array)

Wraps the array as if it was rented.

public static MemoryOwner<T> Create<TArg>(method provider, int length, TArg arg, bool exactSize = true)

public void Dispose()

Releases rented memory.

public bool TryResize(int newLength)

Attempts to resize this buffer without reallocation.