From ebb0ebcab0533ac11379823120dbb777c0601d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Wed, 3 Sep 2025 17:33:55 +0200 Subject: [PATCH] Reduce size of memblock_t structure --- src/z_zone.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 528a2cab8..8ed23e4a7 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -57,11 +57,12 @@ static boolean Z_calloc = false; typedef struct memblock_s { void **user; - INT32 tag; // purgelevel - UINT32 id; // Should be ZONEID + size_t size; // excluding the block - size_t size; // including the header and blocks - size_t realsize; // size of real data only +#ifdef PARANOIA + UINT32 id; // Should be ZONEID +#endif + UINT8 tag; // purgelevel #ifdef ZDEBUG const char *ownerfile; @@ -260,14 +261,15 @@ void *Z_Malloc(size_t size, INT32 tag, void *user) block->ownerline = line; block->ownerfile = file; #endif - block->size = sizeof (memblock_t) + size; - block->realsize = size; + block->size = size; #ifdef VALGRIND_CREATE_MEMPOOL VALGRIND_CREATE_MEMPOOL(block, size, Z_calloc); #endif +#ifdef PARANOIA block->id = ZONEID; +#endif if (user != NULL) { @@ -376,10 +378,10 @@ void *Z_Realloc(void *ptr, size_t size, INT32 tag, void *user) rez = Z_Malloc(size, tag, user); #endif - if (size < block->realsize) + if (size < block->size) copysize = size; else - copysize = block->realsize; + copysize = block->size; M_Memcpy(rez, ptr, copysize); @@ -593,6 +595,7 @@ void Z_CheckHeap(INT32 tag) #endif ); } +#ifdef PARANOIA if (block->id != ZONEID) { I_Error("Z_CheckHeap :" @@ -613,6 +616,7 @@ void Z_CheckHeap(INT32 tag) #endif ); } +#endif } } @@ -706,7 +710,7 @@ size_t Z_TagsUsage(INT32 lowtag, INT32 hightag) { if (rover->tag < lowtag || rover->tag > hightag) continue; - cnt += rover->size + sizeof *rover; + cnt += rover->size + sizeof(memblock_t); } return cnt; @@ -781,7 +785,7 @@ static void Command_Memdump_f(void) if (block->tag >= mintag && block->tag <= maxtag) { const char *filename = strrchr(block->ownerfile, PATHSEP[0]); - CONS_Printf("[%3d] %s (%s) bytes @ %s:%d\n", block->tag, sizeu1(block->size), sizeu2(block->realsize), filename ? filename + 1 : block->ownerfile, block->ownerline); + CONS_Printf("[%3d] %s (%s) bytes @ %s:%d\n", block->tag, sizeu1(block->size + sizeof(memblock_t)), sizeu2(block->size), filename ? filename + 1 : block->ownerfile, block->ownerline); } } #endif