From: divverent Date: Tue, 21 Feb 2012 11:49:25 +0000 (+0000) Subject: no need to waste a full page X-Git-Tag: xonotic-v0.6.0~13 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7a411afa28bd8bf42bd6ae6e0f9b13cf27f9cfa7;p=xonotic%2Fdarkplaces.git no need to waste a full page git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11717 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=cda633ec6a5575333c908bf19cb31c680b32c1c5 --- diff --git a/zone.c b/zone.c index 85a3b219..207132c1 100644 --- a/zone.c +++ b/zone.c @@ -111,16 +111,13 @@ typedef struct mmap_data_s size_t len; } mmap_data_t; -#define MMAP_PAGE_SIZE max(sizeof(mmap_data_t), (size_t)sysconf(_SC_PAGE_SIZE)) static void *mmap_malloc(size_t size) { char vabuf[MAX_OSPATH + 1]; char *tmpdir = getenv("TEMP"); - unsigned char *data; + mmap_data_t *data; int fd; - size += MMAP_PAGE_SIZE; // waste block - size += MMAP_PAGE_SIZE - 1; // also, waste up to this amount for management info - size -= (size % MMAP_PAGE_SIZE); // round down + size += sizeof(mmap-data_t); // waste block dpsnprintf(vabuf, sizeof(vabuf), "%s/darkplaces.XXXXXX", tmpdir ? tmpdir : "/tmp"); fd = mkstemp(vabuf); if(fd < 0) @@ -131,16 +128,16 @@ static void *mmap_malloc(size_t size) unlink(vabuf); if(!data) return NULL; - ((mmap_data_t *) data)->len = size; - return (void *) (data + MMAP_PAGE_SIZE); + data->len = size; + return (void *) (data + 1); } static void mmap_free(void *mem) { - unsigned char *data; + mmap_data_t *data; if(!mem) return; - data = (unsigned char *) mem - MMAP_PAGE_SIZE; - munmap(data, ((mmap_data_t *) data)->len); + data = ((mmap_data_t *) mem) - 1; + munmap(data, data->len); } #define malloc mmap_malloc #define free mmap_free