From cee712105850ac3385cd0091a923438167433f9f Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Sat, 8 Apr 2023 01:22:00 +0200 Subject: Move solution and projects to src --- .../Memory/ByteMemoryPool.ByteMemoryPoolBuffer.cs | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/Ryujinx.Common/Memory/ByteMemoryPool.ByteMemoryPoolBuffer.cs (limited to 'src/Ryujinx.Common/Memory/ByteMemoryPool.ByteMemoryPoolBuffer.cs') diff --git a/src/Ryujinx.Common/Memory/ByteMemoryPool.ByteMemoryPoolBuffer.cs b/src/Ryujinx.Common/Memory/ByteMemoryPool.ByteMemoryPoolBuffer.cs new file mode 100644 index 00000000..eda350bd --- /dev/null +++ b/src/Ryujinx.Common/Memory/ByteMemoryPool.ByteMemoryPoolBuffer.cs @@ -0,0 +1,51 @@ +using System; +using System.Buffers; +using System.Threading; + +namespace Ryujinx.Common.Memory +{ + public sealed partial class ByteMemoryPool + { + /// + /// Represents a that wraps an array rented from + /// and exposes it as + /// with a length of the requested size. + /// + private sealed class ByteMemoryPoolBuffer : IMemoryOwner + { + private byte[] _array; + private readonly int _length; + + public ByteMemoryPoolBuffer(int length) + { + _array = ArrayPool.Shared.Rent(length); + _length = length; + } + + /// + /// Returns a belonging to this owner. + /// + public Memory Memory + { + get + { + byte[] array = _array; + + ObjectDisposedException.ThrowIf(array is null, this); + + return new Memory(array, 0, _length); + } + } + + public void Dispose() + { + var array = Interlocked.Exchange(ref _array, null); + + if (array != null) + { + ArrayPool.Shared.Return(array); + } + } + } + } +} -- cgit v1.2.3