aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Common/Memory/ByteMemoryPool.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.Common/Memory/ByteMemoryPool.cs')
-rw-r--r--src/Ryujinx.Common/Memory/ByteMemoryPool.cs32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/Ryujinx.Common/Memory/ByteMemoryPool.cs b/src/Ryujinx.Common/Memory/ByteMemoryPool.cs
index 071f56b1..6fd6a98a 100644
--- a/src/Ryujinx.Common/Memory/ByteMemoryPool.cs
+++ b/src/Ryujinx.Common/Memory/ByteMemoryPool.cs
@@ -6,24 +6,8 @@ namespace Ryujinx.Common.Memory
/// <summary>
/// Provides a pool of re-usable byte array instances.
/// </summary>
- public sealed partial class ByteMemoryPool
+ public static partial class ByteMemoryPool
{
- private static readonly ByteMemoryPool _shared = new();
-
- /// <summary>
- /// Constructs a <see cref="ByteMemoryPool"/> instance. Private to force access through
- /// the <see cref="ByteMemoryPool.Shared"/> instance.
- /// </summary>
- private ByteMemoryPool()
- {
- // No implementation
- }
-
- /// <summary>
- /// Retrieves a shared <see cref="ByteMemoryPool"/> instance.
- /// </summary>
- public static ByteMemoryPool Shared => _shared;
-
/// <summary>
/// Returns the maximum buffer size supported by this pool.
/// </summary>
@@ -95,6 +79,20 @@ namespace Ryujinx.Common.Memory
return buffer;
}
+ /// <summary>
+ /// Copies <paramref name="buffer"/> into a newly rented byte memory buffer.
+ /// </summary>
+ /// <param name="buffer">The byte buffer to copy</param>
+ /// <returns>A <see cref="IMemoryOwner{Byte}"/> wrapping the rented memory with <paramref name="buffer"/> copied to it</returns>
+ public static IMemoryOwner<byte> RentCopy(ReadOnlySpan<byte> buffer)
+ {
+ var copy = RentImpl(buffer.Length);
+
+ buffer.CopyTo(copy.Memory.Span);
+
+ return copy;
+ }
+
private static ByteMemoryPoolBuffer RentImpl(int length)
{
if ((uint)length > Array.MaxLength)