DotNext by .NET Foundation and Contributors

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

 MemoryRental<T>

public struct MemoryRental<T>
Represents the memory obtained from the pool or allocated on the stack or heap.
public static int StackallocThreshold { get; }

Global recommended number of elements that can be allocated on the stack.

public bool IsEmpty { get; }

Gets a value indicating that this object doesn't reference rented memory.

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

Gets the memory element by its index.

public int Length { get; }

Gets length of the rented memory.

public Span<T> Span { get; }

Gets the rented memory.

public MemoryRental(Span<T> span)

Rents the memory referenced by the span.

public MemoryRental(Span<T> span, int length)

Rents the memory referenced by the span.

public MemoryRental(MemoryPool<T> pool, int minBufferSize, bool exactSize = true)

Rents the memory from the pool.

public MemoryRental(MemoryPool<T> pool)

Rents the memory from the pool.

public MemoryRental(int minBufferSize, bool exactSize = true)

Rents the memory from Shared.

public static MemoryRental<T> op_Implicit(Span<T> span)

Converts the reference to the already allocated memory into the rental object.

public void Dispose()

Returns the memory back to the pool.

public ref T GetPinnableReference()

Obtains managed pointer to the first element of the rented array.