+#ifdef WIN32
+#include <windows.h>
+#include <winbase.h>
+#else
+#include <unistd.h>
+#endif
+
+#ifdef _MSC_VER
+#include <vadefs.h>
+#else
+#include <stdint.h>
+#endif
+#define MEMHEADER_SENTINEL_FOR_ADDRESS(p) ((sentinel_seed ^ (unsigned int) (uintptr_t) (p)) + sentinel_seed)
+unsigned int sentinel_seed;
+
+qboolean mem_bigendian = false;
+
+// LordHavoc: enables our own low-level allocator (instead of malloc)
+#define MEMCLUMPING 0
+#define MEMCLUMPING_FREECLUMPS 0
+
+#if MEMCLUMPING
+// smallest unit we care about is this many bytes
+#define MEMUNIT 128
+// try to do 32MB clumps, but overhead eats into this
+#define MEMWANTCLUMPSIZE (1<<27)
+// give malloc padding so we can't waste most of a page at the end
+#define MEMCLUMPSIZE (MEMWANTCLUMPSIZE - MEMWANTCLUMPSIZE/MEMUNIT/32 - 128)
+#define MEMBITS (MEMCLUMPSIZE / MEMUNIT)
+#define MEMBITINTS (MEMBITS / 32)
+
+typedef struct memclump_s
+{
+ // contents of the clump
+ unsigned char block[MEMCLUMPSIZE];
+ // should always be MEMCLUMP_SENTINEL
+ unsigned int sentinel1;
+ // if a bit is on, it means that the MEMUNIT bytes it represents are
+ // allocated, otherwise free
+ unsigned int bits[MEMBITINTS];
+ // should always be MEMCLUMP_SENTINEL
+ unsigned int sentinel2;
+ // if this drops to 0, the clump is freed
+ size_t blocksinuse;
+ // largest block of memory available (this is reset to an optimistic
+ // number when anything is freed, and updated when alloc fails the clump)
+ size_t largestavailable;
+ // next clump in the chain
+ struct memclump_s *chain;
+}
+memclump_t;
+
+#if MEMCLUMPING == 2
+static memclump_t masterclump;
+#endif
+static memclump_t *clumpchain = NULL;
+#endif
+
+