From 11dc9f516112f2915957328bda860d24bde6acb2 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 7 Sep 2015 22:21:25 -0700 Subject: [PATCH] Libretro: Use anonymous memory mappers for large blocks of memor --- CHANGES | 1 + src/platform/libretro/libretro.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index da17455b2..504fccb97 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,7 @@ Misc: - GBA: Better memory handling with PNG savestates - GBA Audio: Allow GBAAVStream to have no video callback - ARM7: Force disable LTO on two files to work around a GCC bug + - Libretro: Use anonymous memory mappers for large blocks of memory 0.3.0: (2015-08-16) Features: diff --git a/src/platform/libretro/libretro.c b/src/platform/libretro/libretro.c index 172a4541b..0c251b7ab 100644 --- a/src/platform/libretro/libretro.c +++ b/src/platform/libretro/libretro.c @@ -11,6 +11,7 @@ #include "gba/serialize.h" #include "gba/context/context.h" #include "util/circle-buffer.h" +#include "util/memory.h" #include "util/vfs.h" #define SAMPLES 1024 @@ -37,6 +38,7 @@ static void _updateLux(struct GBALuminanceSource* lux); static struct GBAContext context; static struct GBAVideoSoftwareRenderer renderer; static void* data; +static size_t dataSize; static void* savedata; static struct GBAAVStream stream; static int rumbleLevel; @@ -246,7 +248,8 @@ void retro_reset(void) { bool retro_load_game(const struct retro_game_info* game) { struct VFile* rom; if (game->data) { - data = malloc(game->size); + data = anonymousMemoryMap(game->size); + dataSize = game->size; memcpy(data, game->data, game->size); rom = VFileFromMemory(data, game->size); } else { @@ -258,11 +261,11 @@ bool retro_load_game(const struct retro_game_info* game) { } if (!GBAIsROM(rom)) { rom->close(rom); - free(data); + mappedMemoryFree(data, game->size); return false; } - savedata = malloc(SIZE_CART_FLASH1M); + savedata = anonymousMemoryMap(SIZE_CART_FLASH1M); struct VFile* save = VFileFromMemory(savedata, SIZE_CART_FLASH1M); GBAContextLoadROMFromVFile(&context, rom, save); @@ -272,9 +275,9 @@ bool retro_load_game(const struct retro_game_info* game) { void retro_unload_game(void) { GBAContextStop(&context); - free(data); + mappedMemoryFree(data, dataSize); data = 0; - free(savedata); + mappedMemoryFree(savedata, SIZE_CART_FLASH1M); savedata = 0; CircleBufferDeinit(&rumbleHistory); }