From 85e7fc3987340970f2476d2850491e10e5752deb Mon Sep 17 00:00:00 2001 From: Spoike Date: Tue, 23 Nov 2004 00:31:46 +0000 Subject: [PATCH] special sentinal checking and a small optimisation. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@509 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/common/zone.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/engine/common/zone.c b/engine/common/zone.c index b40de1d81..c76944a8e 100644 --- a/engine/common/zone.c +++ b/engine/common/zone.c @@ -34,7 +34,7 @@ void Cache_FreeLow (int new_low_hunk); void Cache_FreeHigh (int new_high_hunk); #ifdef _DEBUG -//#define MEMDEBUG 8192 //Debugging adds sentinels (the number is the size - I have the ram) +#define MEMDEBUG 8192 //Debugging adds sentinels (the number is the size - I have the ram) #endif #ifndef MEMDEBUG @@ -174,6 +174,35 @@ void Z_Free (void *c) free(nz); } +void BZ_CheckSentinals(void *c) +{ +#if MEMDEBUG>0 + zone_t *nz; + nz = ((zone_t *)((char*)c-MEMDEBUG))-1; + +// Z_CheckSentinals(); + { + int i; + qbyte *buf; + buf = (qbyte *)(nz+1); + for (i = 0; i < MEMDEBUG; i++) + { + if (buf[i] != sentinalkey) + *(int*)0 = -3; //force a crash... this'll get our attention. + } + buf+=MEMDEBUG; + //app data + buf += nz->size; + for (i = 0; i < MEMDEBUG; i++) + { + if (buf[i] != sentinalkey) + *(int*)0 = -3; //force a crash... this'll get our attention. + } + } +#endif + +} + void Z_FreeTags(int tag) { zone_t *zone, *next; @@ -301,11 +330,15 @@ void *BZ_Realloc(void *data, int newsize) if (!data) return Z_MallocNamed(newsize, file, lineno); oldzone = ((zone_t *)((char *)data-MEMDEBUG))-1; + if (oldzone->size == newsize) + return data; newdata = Z_MallocNamed(newsize, file, lineno); #else if (!data) return Z_Malloc(newsize); oldzone = ((zone_t *)((char *)data-MEMDEBUG))-1; + if (oldzone->size == newsize) + return data; newdata = BZ_Malloc(newsize); #endif if (oldzone->size < newsize)