@ -49,7 +49,13 @@ public class QuakeParms
public void AllocateMemory(int memorySize)
{
memSize = memorySize;
#if UNITY_GAMECORE
memBase = SystemLibrary.HeapAlloc(SystemLibrary.GetProcessHeap(), 0, new IntPtr(memorySize));
#else
memBase = Marshal.AllocHGlobal(memorySize);
#endif
if (memBase == IntPtr.Zero)
throw new OutOfMemoryException($"Could not allocate {memorySize / 1024 / 1024} MB of heap memory!");
@ -66,7 +72,11 @@ public class QuakeParms
if (memBase != IntPtr.Zero)
SystemLibrary.HeapFree(SystemLibrary.GetProcessHeap(), 0, memBase);
Marshal.FreeHGlobal(memBase);
memBase = IntPtr.Zero;
}
@ -53,4 +53,16 @@ public static class SystemLibrary
[DllImport("SceKernelShim.prx")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32", SetLastError = true)]
public static extern IntPtr GetProcessHeap();
[DllImport("kernel32")]
public static extern IntPtr HeapAlloc(IntPtr hHeap, int dwFlags, IntPtr dwBytes);
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool HeapFree(IntPtr hHeap, int dwFlags, IntPtr lpMem);
@ -5,11 +5,7 @@ using UnityEngine;
public partial class UniQuake: MonoBehaviour
private const int DefaultMemSize = 0x2000000; // Xbox is limited to 32 MB of heap space for now...
private const int DefaultMemSize = 0x8000000; // 128 MB of heap space
public int memorySize = DefaultMemSize;