From c5b7fa7d2b7c3d54bcf37e0d97b26df97f5fec32 Mon Sep 17 00:00:00 2001 From: Tyrann Date: Sun, 1 Oct 2006 20:21:44 +0930 Subject: [PATCH] [PATCH] qbsp: Account size of winding_t allocations Memory stats are reported inaccurately because the memory allocated to windings is not accounted correctly (when freed, in particular). Use the usual technique of recording the allocated size in the same block of memory, just before the portion returned to the caller. Signed-off-by: Tyrann --- qbsp/util.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qbsp/util.c b/qbsp/util.c index 3facb556..8eac1155 100644 --- a/qbsp/util.c +++ b/qbsp/util.c @@ -57,7 +57,7 @@ AllocMem(int Type, int cElements, bool fZero) if (cElements > MAX_POINTS_ON_WINDING) Message(msgError, errTooManyPoints, cElements); - cSize = (int)((winding_t *)0)->points[cElements]; + cSize = (int)((winding_t *)0)->points[cElements] + sizeof(int); // Set cElements to 1 so bookkeeping works OK cElements = 1; @@ -89,6 +89,10 @@ AllocMem(int Type, int cElements, bool fZero) // Special stuff for face_t if (Type == FACE) ((face_t *)pTemp)->planenum = -1; + if (Type == WINDING) { + *(int *)pTemp = cSize; + pTemp = (char *)pTemp + sizeof(int); + } rgMemTotal[Type] += cElements; rgMemActive[Type] += cElements; @@ -114,7 +118,11 @@ void FreeMem(void *pMem, int Type, int cElements) { rgMemActive[Type] -= cElements; - rgMemActive[GLOBAL] -= cElements * rgcMemSize[Type]; + if (Type == WINDING) { + pMem = (char *)pMem - sizeof(int); + rgMemActive[GLOBAL] -= *(int *)pMem; + } else + rgMemActive[GLOBAL] -= cElements * rgcMemSize[Type]; free(pMem); }