#endif
}
-mempool_t *_Mem_AllocPool(const char *name, mempool_t *parent, const char *filename, int fileline)
+mempool_t *_Mem_AllocPool(const char *name, int flags, mempool_t *parent, const char *filename, int fileline)
{
mempool_t *pool;
pool = malloc(sizeof(mempool_t));
pool->sentinel2 = MEMHEADER_SENTINEL1;
pool->filename = filename;
pool->fileline = fileline;
+ pool->flags = flags;
pool->chain = NULL;
pool->totalsize = 0;
pool->realsize = sizeof(mempool_t);
#endif
}
+qboolean Mem_IsAllocated(mempool_t *pool, void *data)
+{
+ memheader_t *header;
+ memheader_t *target;
+
+ target = (memheader_t *)((qbyte *) data - sizeof(memheader_t));
+ for( header = pool->chain ; header ; header = header->next )
+ if( header == target )
+ return true;
+ return false;
+}
+
+
// used for temporary memory allocations around the engine, not for longterm
// storage, if anything in this pool stays allocated during gameplay, it is
// considered a leak
size += pool->totalsize;
}
Con_Printf("%i memory pools, totalling %i bytes (%.3fMB)\n", count, size, size / 1048576.0);
- if (tempmempool == NULL)
- Con_Print("Error: no tempmempool allocated\n");
- else if (tempmempool->chain)
+ for (pool = poolchain;pool;pool = pool->next)
{
- Con_Printf("%i bytes (%.3fMB) of temporary memory still allocated (Leak!)\n", tempmempool->totalsize, tempmempool->totalsize / 1048576.0);
- Con_Print("listing temporary memory allocations:\n");
- for (mem = tempmempool->chain;mem;mem = mem->next)
- Con_Printf("%10i bytes allocated at %s:%i\n", mem->size, mem->filename, mem->fileline);
+ if ((pool->flags & POOLFLAG_TEMP) && pool->chain)
+ {
+ Con_Printf("Memory pool %p has sprung a leak totalling %i bytes (%.3fMB)! Listing contents...\n", pool, pool->totalsize, pool->totalsize / 1048576.0);
+ for (mem = pool->chain;mem;mem = mem->next)
+ Con_Printf("%10i bytes allocated at %s:%i\n", mem->size, mem->filename, mem->fileline);
+ }
}
}
"size name\n");
for (pool = poolchain;pool;pool = pool->next)
{
- if (pool->lastchecksize != 0 && 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("%10ik (%10ik actual) %s\n", (pool->totalsize + 1023) / 1024, (pool->realsize + 1023) / 1024, pool->name);
+ Con_Printf("%10ik (%10ik actual) %s (%+i byte change) %s\n", (pool->totalsize + 1023) / 1024, (pool->realsize + 1023) / 1024, pool->name, pool->totalsize - pool->lastchecksize, (pool->flags & POOLFLAG_TEMP) ? "TEMP" : "");
pool->lastchecksize = pool->totalsize;
if (listallocations)
for (mem = pool->chain;mem;mem = mem->next)
*/
void Memory_Init (void)
{
- tempmempool = Mem_AllocPool("Temporary Memory");
- zonemempool = Mem_AllocPool("Zone");
+ tempmempool = Mem_AllocPool("Temporary Memory", POOLFLAG_TEMP, NULL);
+ zonemempool = Mem_AllocPool("Zone", 0, NULL);
poolchain = NULL;
}