DotNext by Roman Sakno

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

 MemoryOwner<T>

public struct MemoryOwner<T> : IMemoryOwner<T>, IDisposable, ISupplier<Memory<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 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)

Retns 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 void Dispose()

Releases rented memory.

public bool TryGetArray(out ArraySegment segment)

Tries to get an array segment from the underlying memory buffer.