DotNext by Roman Sakno

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

 ArrayRental<T>

public struct ArrayRental<T> : IDisposable
Represents array obtained from array pool.
using System; using System.Buffers; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace DotNext.Buffers { public readonly struct ArrayRental<T> : IDisposable { private readonly ArrayPool<T> pool; private readonly T[] array; private readonly bool clearArray; public ArrayRental(ArrayPool<T> pool, int minimumLength, bool clearArray = false) { this.pool = pool; array = pool.Rent(minimumLength); this.clearArray = clearArray; } public static implicit operator T[]([In] [System.Runtime.CompilerServices.IsReadOnly] ref ArrayRental<T> rental) { return rental.array; } public void Dispose() { pool?.Return(array, clearArray); } } }