Commit 544ba938 authored by CeRiAl's avatar CeRiAl

Added Mamaich's workaround to break out of the 32MB per process memory limit on Windows CE < 6.0

parent bca5cdd9
...@@ -29,6 +29,10 @@ static char rcsid = ...@@ -29,6 +29,10 @@ static char rcsid =
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef UNDER_CE
#include <windows.h>
#endif
#include "SDL_error.h" #include "SDL_error.h"
#include "SDL_video.h" #include "SDL_video.h"
#include "SDL_sysvideo.h" #include "SDL_sysvideo.h"
...@@ -39,6 +43,33 @@ static char rcsid = ...@@ -39,6 +43,33 @@ static char rcsid =
#include "SDL_memops.h" #include "SDL_memops.h"
#include "SDL_leaks.h" #include "SDL_leaks.h"
#ifdef UNDER_CE
static void * ce_virt_malloc (int size)
{
if ( size < 64*1024 ) {
void *Ptr = malloc(size+4);
*((HANDLE*)Ptr) = 0;
return 4+(char*)Ptr;
}
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);
//fprintf(stderr,"%d\n", Ptr);
*((HANDLE*)Ptr) = H;
return 4+(char*)Ptr;
}
static void ce_virt_free (void* addr)
{
HANDLE H = *(HANDLE*)((char *)addr-4);
if ( H == 0 ) {
free((char*)addr-4);
return;
}
UnmapViewOfFile((char *)addr-4);
CloseHandle(H);
}
#endif
/* Public routines */ /* Public routines */
/* /*
* Create an empty RGB surface of the appropriate depth * Create an empty RGB surface of the appropriate depth
...@@ -132,7 +163,11 @@ SDL_Surface * SDL_CreateRGBSurface (Uint32 flags, ...@@ -132,7 +163,11 @@ SDL_Surface * SDL_CreateRGBSurface (Uint32 flags,
if ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) || if ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) ||
(video->AllocHWSurface(this, surface) < 0) ) { (video->AllocHWSurface(this, surface) < 0) ) {
if ( surface->w && surface->h ) { if ( surface->w && surface->h ) {
#ifndef UNDER_CE
surface->pixels = malloc(surface->h*surface->pitch); surface->pixels = malloc(surface->h*surface->pitch);
#else
surface->pixels = ce_virt_malloc(surface->h*surface->pitch);
#endif
if ( surface->pixels == NULL ) { if ( surface->pixels == NULL ) {
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
SDL_OutOfMemory(); SDL_OutOfMemory();
...@@ -940,7 +975,11 @@ void SDL_FreeSurface (SDL_Surface *surface) ...@@ -940,7 +975,11 @@ void SDL_FreeSurface (SDL_Surface *surface)
} }
if ( surface->pixels && if ( surface->pixels &&
((surface->flags & SDL_PREALLOC) != SDL_PREALLOC) ) { ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC) ) {
#ifndef UNDER_CE
free(surface->pixels); free(surface->pixels);
#else
ce_virt_free(surface->pixels);
#endif
} }
free(surface); free(surface);
#ifdef CHECK_LEAKS #ifdef CHECK_LEAKS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment