From d64c223a628aef91401b3e38bcc85e97e3495a32 Mon Sep 17 00:00:00 2001 From: dborth Date: Mon, 1 Jun 2009 21:56:38 +0000 Subject: [PATCH] reduce memory fragmentation with static savebuffer --- source/ngc/fileop.cpp | 16 ++++++++-------- source/ngc/fileop.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index 4c8e55f..4071837 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -33,7 +33,8 @@ #include "filebrowser.h" #include "preferences.h" -unsigned char * savebuffer = NULL; +unsigned char savebuffer[SAVEBUFFERSIZE] ATTRIBUTE_ALIGN(32); +static mutex_t bufferLock = LWP_MUTEX_NULL; FILE * file; // file pointer - the only one we should ever use! bool unmountRequired[9] = { false, false, false, false, false, false, false, false, false }; bool isMounted[9] = { false, false, false, false, false, false, false, false, false }; @@ -417,10 +418,11 @@ ParseDirectory(int method) void AllocSaveBuffer () { - while(savebuffer != NULL) // save buffer is in use - usleep(50); // wait for it to be free + if(bufferLock == LWP_MUTEX_NULL) + LWP_MutexInit(&bufferLock, false); - savebuffer = (unsigned char *) memalign(32, SAVEBUFFERSIZE); + if(bufferLock != LWP_MUTEX_NULL) + LWP_MutexLock(bufferLock); memset (savebuffer, 0, SAVEBUFFERSIZE); } @@ -431,10 +433,8 @@ AllocSaveBuffer () void FreeSaveBuffer () { - if (savebuffer != NULL) - free(savebuffer); - - savebuffer = NULL; + if(bufferLock != LWP_MUTEX_NULL) + LWP_MutexUnlock(bufferLock); } /**************************************************************************** diff --git a/source/ngc/fileop.h b/source/ngc/fileop.h index 237e56c..27cf9e2 100644 --- a/source/ngc/fileop.h +++ b/source/ngc/fileop.h @@ -35,7 +35,7 @@ u32 LoadSzFile(char * filepath, unsigned char * rbuffer); u32 SaveFile(char * buffer, char *filepath, u32 datasize, int method, bool silent); u32 SaveFile(char * filepath, u32 datasize, int method, bool silent); -extern unsigned char * savebuffer; +extern unsigned char savebuffer[]; extern FILE * file; extern bool unmountRequired[]; extern bool isMounted[];