#endif
}
-mempool_t *_Mem_AllocPool(const char *name, const char *filename, int fileline)
+mempool_t *_Mem_AllocPool(const char *name, mempool_t *parent, const char *filename, int fileline)
{
mempool_t *pool;
pool = malloc(sizeof(mempool_t));
pool->totalsize = 0;
pool->realsize = sizeof(mempool_t);
strlcpy (pool->name, name, sizeof (pool->name));
+ pool->parent = parent;
pool->next = poolchain;
poolchain = pool;
return pool;
void _Mem_FreePool(mempool_t **pool, const char *filename, int fileline)
{
- mempool_t **chainaddress;
+ mempool_t **chainaddress, *iter, *temp;
+
if (*pool)
{
if ((*pool)->sentinel1 != MEMHEADER_SENTINEL1)
while ((*pool)->chain)
Mem_Free((void *)((qbyte *) (*pool)->chain + sizeof(memheader_t)));
+ // free child pools, too
+ for(iter = poolchain; iter; temp = iter = iter->next)
+ if(iter->parent == *pool)
+ _Mem_FreePool(&temp, filename, fileline);
+
// free the pool itself
memset(*pool, 0xBF, sizeof(mempool_t));
free(*pool);
void _Mem_EmptyPool(mempool_t *pool, const char *filename, int fileline)
{
+ mempool_t *chainaddress;
+
if (pool == NULL)
Sys_Error("Mem_EmptyPool: pool == NULL (emptypool at %s:%i)", filename, fileline);
if (pool->sentinel1 != MEMHEADER_SENTINEL1)
// free memory owned by the pool
while (pool->chain)
Mem_Free((void *)((qbyte *) pool->chain + sizeof(memheader_t)));
+
+ // empty child pools, too
+ for(chainaddress = poolchain; chainaddress; chainaddress = chainaddress->next)
+ if(chainaddress->parent == pool)
+ _Mem_EmptyPool(chainaddress, filename, fileline);
+
}
void _Mem_CheckSentinels(void *data, const char *filename, int fileline)
{
tempmempool = Mem_AllocPool("Temporary Memory");
zonemempool = Mem_AllocPool("Zone");
+ poolchain = NULL;
}
void Memory_Init_Commands (void)