Initial commit
This commit is contained in:
commit
ef3b7d68fb
30 changed files with 1568 additions and 0 deletions
29
Infra/Buffers/ArrayOwner.cs
Normal file
29
Infra/Buffers/ArrayOwner.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System.Buffers;
|
||||
|
||||
namespace StitchATon2.Infra.Buffers;
|
||||
|
||||
public class ArrayOwner<T> : IBuffer<T> where T : unmanaged
|
||||
{
|
||||
private readonly ArrayPool<T> _owner;
|
||||
private readonly T[] _buffer;
|
||||
|
||||
public ArrayOwner(ArrayPool<T> owner, int size)
|
||||
{
|
||||
_owner = owner;
|
||||
_buffer = owner.Rent(size);
|
||||
}
|
||||
|
||||
~ArrayOwner() => Dispose();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_owner.Return(_buffer);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public ref T this[int index] => ref _buffer[index];
|
||||
|
||||
public Span<T> Span => _buffer;
|
||||
|
||||
public T[] Array => _buffer;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue