]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - zone.c
huge (16%) speed gain on surface rendering by eliminating the surfmesh chain in q1bsp...
[xonotic/darkplaces.git] / zone.c
diff --git a/zone.c b/zone.c
index 941f93277ccb08d3def511e43a0d799c87c23b55..a68c136edebacb53e422b02ced1b9e620d7665a5 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -21,6 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "quakedef.h"
 
+cvar_t developer_memory = {0, "developer_memory", "0"};
+cvar_t developer_memorydebug = {0, "developer_memorydebug", "0"};
+
 mempool_t *poolchain = NULL;
 
 void *_Mem_Alloc(mempool_t *pool, int size, const char *filename, int fileline)
@@ -34,7 +37,10 @@ void *_Mem_Alloc(mempool_t *pool, int size, const char *filename, int fileline)
                return NULL;
        if (pool == NULL)
                Sys_Error("Mem_Alloc: pool == NULL (alloc at %s:%i)", filename, fileline);
-       Con_DPrintf("Mem_Alloc: pool %s, file %s:%i, size %i bytes\n", pool->name, filename, fileline, size);
+       if (developer.integer && developer_memory.integer)
+               Con_Printf("Mem_Alloc: pool %s, file %s:%i, size %i bytes\n", pool->name, filename, fileline, size);
+       if (developer.integer && developer_memorydebug.integer)
+               _Mem_CheckSentinelsGlobal(filename, fileline);
        pool->totalsize += size;
 #if MEMCLUMPING
        if (size < 4096)
@@ -136,7 +142,8 @@ void _Mem_Free(void *data, const char *filename, int fileline)
        if (*((qbyte *) mem + sizeof(memheader_t) + mem->size) != MEMHEADER_SENTINEL2)
                Sys_Error("Mem_Free: trashed header sentinel 2 (alloc at %s:%i, free at %s:%i)", mem->filename, mem->fileline, filename, fileline);
        pool = mem->pool;
-       Con_DPrintf("Mem_Free: pool %s, alloc %s:%i, free %s:%i, size %i bytes\n", pool->name, mem->filename, mem->fileline, filename, fileline, mem->size);
+       if (developer.integer && developer_memory.integer)
+               Con_Printf("Mem_Free: pool %s, alloc %s:%i, free %s:%i, size %i bytes\n", pool->name, mem->filename, mem->fileline, filename, fileline, mem->size);
        // unlink memheader from doubly linked list
        if ((mem->prev ? mem->prev->next != mem : pool->chain != mem) || (mem->next && mem->next->prev != mem))
                Sys_Error("Mem_Free: not allocated or double freed (free at %s:%i)", filename, fileline);
@@ -346,9 +353,9 @@ void Mem_PrintList(int listallocations)
        for (pool = poolchain;pool;pool = pool->next)
        {
                if (pool->lastchecksize != 0 && pool->totalsize != pool->lastchecksize)
-                       Con_Printf("%6ik (%6ik actual) %s (%i byte change)\n", (pool->totalsize + 1023) / 1024, (pool->realsize + 1023) / 1024, pool->name, pool->totalsize - pool->lastchecksize);
+                       Con_Printf("%10ik (%10ik actual) %s (%i byte change)\n", (pool->totalsize + 1023) / 1024, (pool->realsize + 1023) / 1024, pool->name, pool->totalsize - pool->lastchecksize);
                else
-                       Con_Printf("%6ik (%6ik actual) %s\n", (pool->totalsize + 1023) / 1024, (pool->realsize + 1023) / 1024, pool->name);
+                       Con_Printf("%10ik (%10ik actual) %s\n", (pool->totalsize + 1023) / 1024, (pool->realsize + 1023) / 1024, pool->name);
                pool->lastchecksize = pool->totalsize;
                if (listallocations)
                        for (mem = pool->chain;mem;mem = mem->next)
@@ -402,5 +409,7 @@ void Memory_Init_Commands (void)
 {
        Cmd_AddCommand ("memstats", MemStats_f);
        Cmd_AddCommand ("memlist", MemList_f);
+       Cvar_RegisterVariable (&developer_memory);
+       Cvar_RegisterVariable (&developer_memorydebug);
 }