Skip to content

Instantly share code, notes, and snippets.

@JKamsker
Last active June 13, 2024 07:02
Show Gist options
  • Save JKamsker/27f65465d401b03e68f3822406227285 to your computer and use it in GitHub Desktop.
Save JKamsker/27f65465d401b03e68f3822406227285 to your computer and use it in GitHub Desktop.
BufferOwner.cs
public readonly struct BufferOwner<T> : IDisposable
{
private readonly T[] _buffer;
private readonly ArrayPool<T> _pool;
public BufferOwner(int size, ArrayPool<T> pool)
{
_buffer = pool.Rent(size);
_pool = pool;
}
public T[] Buffer => _buffer;
public void Dispose()
{
_pool.Return(_buffer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment