From 4bad28046b6aae3ff33e72a70333a4871a139d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 9 Mar 2017 14:35:12 +0100 Subject: [PATCH] UWP: Save memory by only committing the ranges we need, instead of doing a giant allocation. --- Common/MemArenaWin32.cpp | 8 ++++---- Core/MemMap.cpp | 23 +++++++++++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Common/MemArenaWin32.cpp b/Common/MemArenaWin32.cpp index 58f70a3528..437bfd33d9 100644 --- a/Common/MemArenaWin32.cpp +++ b/Common/MemArenaWin32.cpp @@ -42,13 +42,13 @@ void MemArena::ReleaseSpace() { hMemoryMapping = 0; } -void *MemArena::CreateView(s64 offset, size_t size, void *base) { +void *MemArena::CreateView(s64 offset, size_t size, void *viewbase) { size = roundup(size); #if PPSSPP_PLATFORM(UWP) - // Can't map views properly. We just grab some RAM. - void *ptr = VirtualAllocFromApp(NULL, size, MEM_COMMIT, PAGE_READWRITE); + // We just grabbed some RAM before using RESERVE. This commits it. + void *ptr = VirtualAllocFromApp(viewbase, size, MEM_COMMIT, PAGE_READWRITE); #else - void *ptr = MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, base); + void *ptr = MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, viewbase); #endif return ptr; } diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index 1584d2537a..6f324e6e3c 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -17,6 +17,10 @@ #include "ppsspp_config.h" +#if PPSSPP_PLATFORM(UWP) +#include "Common/CommonWindows.h" +#endif + #include #include @@ -129,7 +133,6 @@ inline static bool CanIgnoreView(const MemoryView &view) { ; #endif -#if !PPSSPP_PLATFORM(UWP) static bool Memory_TryBase(u32 flags) { // OK, we know where to find free space. Now grab it! // We just mimic the popular BAT setup. @@ -153,7 +156,7 @@ static bool Memory_TryBase(u32 flags) { if (view.flags & MV_MIRROR_PREVIOUS) { position = last_position; } -#if PPSSPP_ARCH(64BIT) +#ifndef MASKED_PSP_MEMORY *view.out_ptr = (u8*)g_arena.CreateView( position, view.size, base + view.virtual_address); if (!*view.out_ptr) { @@ -193,19 +196,13 @@ bail: } return false; } -#endif bool MemoryMap_Setup(u32 flags) { #if PPSSPP_PLATFORM(UWP) - // We just grab all 256MB. - // We should be able to avoid COMMIT-ing here, TODO. - base = (u8*)VirtualAllocFromApp(0, 0x10000000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); - for (int i = 0; i < num_views; i++) { - const MemoryView &view = views[i]; - (*view.out_ptr) = (uint8_t *)base + (views[i].virtual_address & Memory::MEMVIEW32_MASK); - } - return true; + // We reserve the memory, then simply commit in TryBase. + base = (u8*)VirtualAllocFromApp(0, 0x10000000, MEM_RESERVE, PAGE_READWRITE); #else + // Figure out how much memory we need to allocate in total. size_t total_mem = 0; for (int i = 0; i < num_views; i++) { @@ -218,6 +215,7 @@ bool MemoryMap_Setup(u32 flags) { // Grab some pagefile backed memory out of the void ... g_arena.GrabLowMemSpace(total_mem); +#endif #if !PPSSPP_PLATFORM(ANDROID) if (g_arena.NeedsProbing()) { @@ -248,12 +246,13 @@ bool MemoryMap_Setup(u32 flags) { else #endif { +#if !PPSSPP_PLATFORM(UWP) base = g_arena.Find4GBBase(); +#endif } // Should return true... return Memory_TryBase(flags); -#endif } void MemoryMap_Shutdown(u32 flags) {