Last active
June 13, 2024 07:02
-
-
Save JKamsker/27f65465d401b03e68f3822406227285 to your computer and use it in GitHub Desktop.
BufferOwner.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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