aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Cpu/MemoryHelper.cs
diff options
context:
space:
mode:
authorjhorv <38920027+jhorv@users.noreply.github.com>2023-03-17 08:14:50 -0400
committerGitHub <noreply@github.com>2023-03-17 13:14:50 +0100
commit5131b71437b36f9b876046a2fddd5465652e0f10 (patch)
treea1b8647b1f948e3f88708d9ba41b2d1338f34de9 /Ryujinx.Cpu/MemoryHelper.cs
parent7870423671cba17c8aad9bb93a67c84bda441366 (diff)
Reducing memory allocations (#4537)1.1.668
* add RecyclableMemoryStream dependency and MemoryStreamManager * organize BinaryReader/BinaryWriter extensions * add StreamExtensions to reduce need for BinaryWriter * simple replacments of MemoryStream with RecyclableMemoryStream * add write ReadOnlySequence<byte> support to IVirtualMemoryManager * avoid 0-length array creation * rework IpcMessage and related types to greatly reduce memory allocation by using RecylableMemoryStream, keeping streams around longer, avoiding their creation when possible, and avoiding creation of BinaryReader and BinaryWriter when possible * reduce LINQ-induced memory allocations with custom methods to query KPriorityQueue * use RecyclableMemoryStream in StreamUtils, and use StreamUtils in EmbeddedResources * add constants for nanosecond/millisecond conversions * code formatting * XML doc adjustments * fix: StreamExtension.WriteByte not writing non-zero values for lengths <= 16 * XML Doc improvements. Implement StreamExtensions.WriteByte() block writes for large-enough count values. * add copyless path for StreamExtension.Write(ReadOnlySpan<int>) * add default implementation of IVirtualMemoryManager.Write(ulong, ReadOnlySequence<byte>); remove previous explicit implementations * code style fixes * remove LINQ completely from KScheduler/KPriorityQueue by implementing a custom struct-based enumerator
Diffstat (limited to 'Ryujinx.Cpu/MemoryHelper.cs')
-rw-r--r--Ryujinx.Cpu/MemoryHelper.cs8
1 files changed, 5 insertions, 3 deletions
diff --git a/Ryujinx.Cpu/MemoryHelper.cs b/Ryujinx.Cpu/MemoryHelper.cs
index 64ff360e..194a0c35 100644
--- a/Ryujinx.Cpu/MemoryHelper.cs
+++ b/Ryujinx.Cpu/MemoryHelper.cs
@@ -1,4 +1,6 @@
-using Ryujinx.Memory;
+using Microsoft.IO;
+using Ryujinx.Common.Memory;
+using Ryujinx.Memory;
using System;
using System.IO;
using System.Runtime.CompilerServices;
@@ -40,7 +42,7 @@ namespace Ryujinx.Cpu
public static string ReadAsciiString(IVirtualMemoryManager memory, ulong position, long maxSize = -1)
{
- using (MemoryStream ms = new MemoryStream())
+ using (RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream())
{
for (long offs = 0; offs < maxSize || maxSize == -1; offs++)
{
@@ -54,7 +56,7 @@ namespace Ryujinx.Cpu
ms.WriteByte(value);
}
- return Encoding.ASCII.GetString(ms.ToArray());
+ return Encoding.ASCII.GetString(ms.GetReadOnlySequence());
}
}
}