diff options
author | CeRiAl | 2011-10-18 13:10:20 +0200 |
---|---|---|
committer | CeRiAl | 2011-10-18 13:10:20 +0200 |
commit | a97cd0077fbe2df315a9356e38b39a5065b77c02 (patch) | |
tree | 9437da60a9203d3918c56848bcad265f06bb442f /backends/platform/wince/wince-sdl.cpp | |
parent | 757c522dd1a9ed431e6621dabed776211651ff31 (diff) | |
download | scummvm-rg350-a97cd0077fbe2df315a9356e38b39a5065b77c02.tar.gz scummvm-rg350-a97cd0077fbe2df315a9356e38b39a5065b77c02.tar.bz2 scummvm-rg350-a97cd0077fbe2df315a9356e38b39a5065b77c02.zip |
WINCE: Add workaround for memory management problem on Windows CE < 6.0
This fixes the "32MB memory limit per process" problem in Windows CE < 6.0
Diffstat (limited to 'backends/platform/wince/wince-sdl.cpp')
-rw-r--r-- | backends/platform/wince/wince-sdl.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp index 1abc3cb350..4e17827e5c 100644 --- a/backends/platform/wince/wince-sdl.cpp +++ b/backends/platform/wince/wince-sdl.cpp @@ -72,6 +72,50 @@ extern "C" _CRTIMP FILE *__cdecl _wfreopen(const wchar_t *, const wchar_t *, FILE *); #endif +#ifdef WRAP_MALLOC + +extern "C" void *__real_malloc(size_t size); +extern "C" void __real_free(void *ptr); + +extern "C" void *__wrap_malloc(size_t size) { +/* + void *ptr = __real_malloc(size); + printf("malloc(%d) = %p\n", size, ptr); + return ptr; +*/ + if (size < 64 * 1024) { + void *ptr = __real_malloc(size+4); +// printf("malloc(%d) = %p\n", size, ptr); + if (ptr != NULL) { + *((HANDLE*)ptr) = 0; + return 4+(char*)ptr; + } + return NULL; + } + HANDLE H = CreateFileMapping((HANDLE)INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size+4, 0); + void *ptr = MapViewOfFile(H, FILE_MAP_ALL_ACCESS, 0, 0, 0); + *((HANDLE*)ptr) = H; + return 4+(char*)ptr; +} + +extern "C" void __wrap_free(void *ptr) { +/* + __real_free(ptr); + printf("free(%p)\n", ptr); +*/ + if (ptr != NULL) { + HANDLE H = *(HANDLE*)((char *)ptr-4); + if (H == 0) { + __real_free((char*)ptr-4); + return; + } + UnmapViewOfFile((char *)ptr-4); + CloseHandle(H); + } +} + +#endif + using namespace CEGUI; // ******************************************************************************************** |