mirror of
https://github.com/dborth/fceugx.git
synced 2025-01-05 21:38:17 +01:00
reduce memory fragmentation with static savebuffer
This commit is contained in:
parent
52ee05ab0f
commit
f5563ce001
@ -32,7 +32,8 @@
|
||||
#include "menu.h"
|
||||
#include "filebrowser.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 };
|
||||
@ -416,10 +417,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);
|
||||
}
|
||||
|
||||
@ -430,10 +432,8 @@ AllocSaveBuffer ()
|
||||
void
|
||||
FreeSaveBuffer ()
|
||||
{
|
||||
if (savebuffer != NULL)
|
||||
free(savebuffer);
|
||||
|
||||
savebuffer = NULL;
|
||||
if(bufferLock != LWP_MUTEX_NULL)
|
||||
LWP_MutexUnlock(bufferLock);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -36,7 +36,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[];
|
||||
|
Loading…
Reference in New Issue
Block a user