Browse Source

Use HeapAlloc to allocate hunk memory for the engine on Xbox. This reserves memory from the title's pool as opposed to the system's pool, which allows us to get the full 128 MB (or more) that we desire.

console
Nico de Poel 5 years ago
parent
commit
19f63f4794
  1. 10
      Assets/Scripts/QuakeParms.cs
  2. 12
      Assets/Scripts/SystemLibrary.cs
  3. 4
      Assets/Scripts/UniQuake.cs

10
Assets/Scripts/QuakeParms.cs

@ -49,7 +49,13 @@ public class QuakeParms
public void AllocateMemory(int memorySize) public void AllocateMemory(int memorySize)
{ {
memSize = memorySize; memSize = memorySize;
#if UNITY_GAMECORE
memBase = SystemLibrary.HeapAlloc(SystemLibrary.GetProcessHeap(), 0, new IntPtr(memorySize));
#else
memBase = Marshal.AllocHGlobal(memorySize); memBase = Marshal.AllocHGlobal(memorySize);
#endif
if (memBase == IntPtr.Zero) if (memBase == IntPtr.Zero)
{ {
throw new OutOfMemoryException($"Could not allocate {memorySize / 1024 / 1024} MB of heap memory!"); throw new OutOfMemoryException($"Could not allocate {memorySize / 1024 / 1024} MB of heap memory!");
@ -66,7 +72,11 @@ public class QuakeParms
if (memBase != IntPtr.Zero) if (memBase != IntPtr.Zero)
{ {
#if UNITY_GAMECORE
SystemLibrary.HeapFree(SystemLibrary.GetProcessHeap(), 0, memBase);
#else
Marshal.FreeHGlobal(memBase); Marshal.FreeHGlobal(memBase);
#endif
memBase = IntPtr.Zero; memBase = IntPtr.Zero;
} }

12
Assets/Scripts/SystemLibrary.cs

@ -53,4 +53,16 @@ public static class SystemLibrary
[DllImport("SceKernelShim.prx")] [DllImport("SceKernelShim.prx")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
#endif #endif
#if UNITY_GAMECORE
[DllImport("kernel32", SetLastError = true)]
public static extern IntPtr GetProcessHeap();
[DllImport("kernel32")]
public static extern IntPtr HeapAlloc(IntPtr hHeap, int dwFlags, IntPtr dwBytes);
[DllImport("kernel32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool HeapFree(IntPtr hHeap, int dwFlags, IntPtr lpMem);
#endif
} }

4
Assets/Scripts/UniQuake.cs

@ -5,11 +5,7 @@ using UnityEngine;
public partial class UniQuake: MonoBehaviour public partial class UniQuake: MonoBehaviour
{ {
#if UNITY_GAMECORE
private const int DefaultMemSize = 0x2000000; // Xbox is limited to 32 MB of heap space for now...
#else
private const int DefaultMemSize = 0x8000000; // 128 MB of heap space private const int DefaultMemSize = 0x8000000; // 128 MB of heap space
#endif
public int memorySize = DefaultMemSize; public int memorySize = DefaultMemSize;

Loading…
Cancel
Save