summaryrefslogtreecommitdiff
path: root/src/i_system.c
diff options
context:
space:
mode:
authorSimon Howard2009-07-09 17:50:04 +0000
committerSimon Howard2009-07-09 17:50:04 +0000
commitd06dcf916776e58b1f476cf9320b5274a28957b1 (patch)
tree8105769fc715d0cdcbf4c9a6b20d1a92250d7ee6 /src/i_system.c
parentd91e3e86736f710265629e56dc77c1dec0b425e7 (diff)
parent24783792e5398a2d5af6b7220b68c46357d23e31 (diff)
downloadchocolate-doom-d06dcf916776e58b1f476cf9320b5274a28957b1.tar.gz
chocolate-doom-d06dcf916776e58b1f476cf9320b5274a28957b1.tar.bz2
chocolate-doom-d06dcf916776e58b1f476cf9320b5274a28957b1.zip
Merge from trunk.
Subversion-branch: /branches/raven-branch Subversion-revision: 1610
Diffstat (limited to 'src/i_system.c')
-rw-r--r--src/i_system.c50
1 files changed, 36 insertions, 14 deletions
diff --git a/src/i_system.c b/src/i_system.c
index 0ec8e185..c6deb905 100644
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -55,6 +55,8 @@
#include "w_wad.h"
#include "z_zone.h"
+#define MIN_RAM 4 /* MiB */
+
int mb_used = 16;
typedef struct atexit_listentry_s atexit_listentry_t;
@@ -86,8 +88,10 @@ void I_Tactile(int on, int off, int total)
{
}
-int I_GetHeapSize (void)
+byte *I_ZoneBase (int *size)
{
+ byte *zonemem;
+ int min_ram = MIN_RAM;
int p;
//!
@@ -97,28 +101,46 @@ int I_GetHeapSize (void)
//
p = M_CheckParm("-mb");
-
+
if (p > 0)
{
mb_used = atoi(myargv[p+1]);
+ min_ram = mb_used;
}
-
- return mb_used*1024*1024;
-}
-
-byte *I_ZoneBase (int *size)
-{
- byte *zonemem;
- *size = I_GetHeapSize();
+ // Allocate the zone memory. This loop tries progressively smaller
+ // zone sizes until a size is found that can be allocated.
+ // If we used the -mb command line parameter, only the parameter
+ // provided is accepted.
- zonemem = malloc(*size);
+ zonemem = NULL;
- if (zonemem == NULL)
+ while (zonemem == NULL)
{
- I_Error("Failed to allocate %i bytes for zone memory", *size);
+ // We need a reasonable minimum amount of RAM to start.
+
+ if (mb_used < min_ram)
+ {
+ I_Error("Unable to allocate %i MiB of RAM for zone", mb_used);
+ }
+
+ // Try to allocate the zone memory.
+
+ *size = mb_used * 1024 * 1024;
+
+ zonemem = malloc(*size);
+
+ // Failed to allocate? Reduce zone size until we reach a size
+ // that is acceptable. We decrease by 2 MiB at a time to ensure
+ // that there is 1-2 MiB still free on the system (my Windows
+ // Mobile PDA becomes unstable if very low on memory)
+
+ if (zonemem == NULL)
+ {
+ mb_used -= 2;
+ }
}
-
+
printf("zone memory: %p, %x allocated for zone\n",
zonemem, *size);