From 1ee5547bb2ea801a2ad31b65389a58634f4df1f7 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Fri, 13 Dec 2024 10:55:22 -0600 Subject: [PATCH] Allocate imgbuf on-demand in Picture_PatchConvert This static var requires a 64 megabyte .bss section value which is allocated on application startup. Depending on the particulars of the operating system's virtual memory implementation, this may result in dynamic page allocation for the span, or a full upfront allocation. Either way, it doesn't need to be like this, we can just dynamically allocate the buffer instead. This may save up to 64MiB of runtime memory usage. --- src/r_picformats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_picformats.c b/src/r_picformats.c index 7eed58392..84503d365 100644 --- a/src/r_picformats.c +++ b/src/r_picformats.c @@ -52,8 +52,6 @@ #endif #endif -static unsigned char imgbuf[1<<26]; - #ifdef PICTURE_PNG_USELOOKUP static colorlookup_t png_colorlookup; #endif @@ -119,6 +117,7 @@ void *Picture_PatchConvert( { INT16 x, y; UINT8 *img; + UINT8 *imgbuf = Z_Malloc(1<<26, PU_STATIC, NULL); UINT8 *imgptr = imgbuf; UINT8 *colpointers, *startofspan; size_t size = 0; @@ -352,6 +351,7 @@ void *Picture_PatchConvert( size = imgptr-imgbuf; img = Z_Malloc(size, PU_STATIC, NULL); memcpy(img, imgbuf, size); + Z_Free(imgbuf); if (Picture_IsInternalPatchFormat(outformat)) {