engine: zone: optimize memory usage a bit by compressing memheader_t better while keeping it efficient

It saves about 40 kilobytes of memory.
This commit is contained in:
Alibek Omarov 2025-01-21 14:04:13 +03:00
parent 232d1f8583
commit 8a9b209db0

View file

@ -18,7 +18,7 @@ GNU General Public License for more details.
#include "common.h" #include "common.h"
#define MEMHEADER_SENTINEL1 0xDEADF00DU #define MEMHEADER_SENTINEL1 0xA1BAU
#define MEMHEADER_SENTINEL2 0xDFU #define MEMHEADER_SENTINEL2 0xDFU
#ifdef XASH_CUSTOM_SWAP #ifdef XASH_CUSTOM_SWAP
@ -51,31 +51,29 @@ static void *Q_realloc( void *mem, size_t size )
#define Q_realloc realloc #define Q_realloc realloc
#endif #endif
// keep this structure as compact as possible while keeping it aligned
// on ILP32 it's 24 bytes, which is aligned to 8 byte boundary
// on LP64 it's 40 bytes, which is also aligned to 8 byte boundary
typedef struct memheader_s typedef struct memheader_s
{ {
struct memheader_s *next; // next and previous memheaders in chain belonging to pool struct memheader_s *next, *prev; // next and previous memheaders in chain belonging to pool
struct memheader_s *prev; const char *filename; // file name and line where Mem_Alloc was called
const char *filename; // file name and line where Mem_Alloc was called size_t size; // size of the memory after the header (excluding header and sentinel2)
size_t size; // size of the memory after the header (excluding header and sentinel2) poolhandle_t poolptr; // pool this memheader belongs to
poolhandle_t poolptr; // pool this memheader belongs to uint16_t fileline;
int fileline; uint16_t sentinel1; // must be equal to MEMHEADER_SENTINEL1
#if !XASH_64BIT
uint32_t pad0; // doesn't have value, only to make Mem_Alloc return aligned addresses on ILP32
#endif
uint32_t sentinel1; // should always be MEMHEADER_SENTINEL1
// immediately followed by data, which is followed by a MEMHEADER_SENTINEL2 byte // immediately followed by data, which is followed by a MEMHEADER_SENTINEL2 byte
} memheader_t; } memheader_t;
typedef struct mempool_s typedef struct mempool_s
{ {
struct memheader_s *chain; // chain of individual memory allocations struct memheader_s *chain; // chain of individual memory allocations
size_t totalsize; // total memory allocated in this pool (inside memheaders) size_t totalsize; // total memory allocated in this pool (inside memheaders)
size_t realsize; // total memory allocated in this pool (actual malloc total) size_t realsize; // total memory allocated in this pool (actual malloc total)
size_t lastchecksize; // updated each time the pool is displayed by memlist size_t lastchecksize; // updated each time the pool is displayed by memlist
const char *filename; // file name and line where Mem_AllocPool was called const char *filename; // file name and line where Mem_AllocPool was called
int fileline; int fileline;
char name[64]; // name of the pool char name[64]; // name of the pool
} mempool_t; } mempool_t;
static mempool_t *poolchain = NULL; // critical stuff static mempool_t *poolchain = NULL; // critical stuff