using System.Buffers; namespace StitchATon2.Infra.Buffers; public class ArrayOwner : IBuffer where T : unmanaged { private readonly ArrayPool _owner; private readonly T[] _buffer; public ArrayOwner(ArrayPool owner, int length) { _owner = owner; _buffer = owner.Rent(length); Length = length; } ~ArrayOwner() => Dispose(); public void Dispose() { _owner.Return(_buffer); GC.SuppressFinalize(this); } public ref T this[int index] => ref _buffer[index]; public Span Span => _buffer; public T[] Array => _buffer; public int Length { get; } }