void CL_CGVM_Init(void)
{
- cgvm_mempool = Mem_AllocPool("CGVM");
+ cgvm_mempool = Mem_AllocPool("CGVM", 0, NULL);
}
void CL_CGVM_Clear(void)
*/
void CL_Init (void)
{
- cl_entities_mempool = Mem_AllocPool("client entities");
- cl_refdef_mempool = Mem_AllocPool("refdef");
+ cl_entities_mempool = Mem_AllocPool("client entities", 0, NULL);
+ cl_refdef_mempool = Mem_AllocPool("refdef", 0, NULL);
memset(&r_refdef, 0, sizeof(r_refdef));
// max entities sent to renderer per frame
void CL_Parse_Init(void)
{
// LordHavoc: added demo_nehahra cvar
- cl_scores_mempool = Mem_AllocPool("client player info");
+ cl_scores_mempool = Mem_AllocPool("client player info", 0, NULL);
Cvar_RegisterVariable (&demo_nehahra);
if (gamemode == GAME_NEHAHRA)
Cvar_SetValue("demo_nehahra", 1);
#ifdef WORKINGLQUAKE
particles = (particle_t *) Hunk_AllocName(cl_maxparticles * sizeof(particle_t), "particles");
#else
- cl_part_mempool = Mem_AllocPool("CL_Part");
+ cl_part_mempool = Mem_AllocPool("CL_Part", 0, NULL);
particles = (particle_t *) Mem_Alloc(cl_part_mempool, cl_maxparticles * sizeof(particle_t));
#endif
cl_numparticles = 0;
Cmd_AddCommand("playvideo", CL_PlayVideo_f);
Cmd_AddCommand("stopvideo", CL_StopVideo_f);
- clvideomempool = Mem_AllocPool("CL_Video");
+ clvideomempool = Mem_AllocPool("CL_Video", 0, NULL);
}
*/
void Cmd_Init (void)
{
- cmd_mempool = Mem_AllocPool("commands");
+ cmd_mempool = Mem_AllocPool("commands", 0, NULL);
//
// register our commands
{
if (startsize < 256)
startsize = 256;
- buf->mempool = Mem_AllocPool(name);
+ buf->mempool = Mem_AllocPool(name, 0, NULL);
buf->data = Mem_Alloc(buf->mempool, startsize);
buf->maxsize = startsize;
buf->cursize = 0;
*/
void Con_Init (void)
{
- console_mempool = Mem_AllocPool("console");
+ console_mempool = Mem_AllocPool("console", 0, NULL);
con_text = Mem_Alloc(console_mempool, CON_TEXTSIZE);
memset (con_text, ' ', CON_TEXTSIZE);
con_linewidth = -1;
strlcpy (pack->filename, packfile, sizeof (pack->filename));
pack->handle = packhandle;
pack->numfiles = eocd.nbentries;
- pack->mempool = Mem_AllocPool (packfile);
+ pack->mempool = Mem_AllocPool (packfile, 0, NULL);
pack->files = Mem_Alloc (pack->mempool, eocd.nbentries * sizeof(packfile_t));
pack->next = packlist;
packlist = pack;
strlcpy (pack->filename, packfile, sizeof (pack->filename));
pack->handle = packhandle;
pack->numfiles = 0;
- pack->mempool = Mem_AllocPool(packfile);
+ pack->mempool = Mem_AllocPool(packfile, 0, NULL);
pack->files = Mem_Alloc(pack->mempool, numpackfiles * sizeof(packfile_t));
pack->next = packlist;
packlist = pack;
int i;
searchpath_t *search;
- fs_mempool = Mem_AllocPool("file management");
- pak_mempool = Mem_AllocPool("paks");
+ fs_mempool = Mem_AllocPool("file management", 0, NULL);
+ pak_mempool = Mem_AllocPool("paks", 0, NULL);
Cvar_RegisterVariable (&scr_screenshot_name);
void GL_Backend_AllocArrays(void)
{
if (!gl_backend_mempool)
- gl_backend_mempool = Mem_AllocPool("GL_Backend");
+ gl_backend_mempool = Mem_AllocPool("GL_Backend", 0, NULL);
R_Mesh_CacheArray_Startup();
}
void gl_models_start(void)
{
// allocate vertex processing arrays
- gl_models_mempool = Mem_AllocPool("GL_Models");
+ gl_models_mempool = Mem_AllocPool("GL_Models", 0, NULL);
zymbonepose = Mem_Alloc(gl_models_mempool, sizeof(zymbonematrix[256]));
gl_models_allocarrays(4096);
}
// use the largest scrap texture size we can (not sure if this is really a good idea)
for (block_size = 1;block_size < realmaxsize && block_size < gl_max_scrapsize.integer;block_size <<= 1);
- texturemempool = Mem_AllocPool("Texture Info");
- texturedatamempool = Mem_AllocPool("Texture Storage (not yet uploaded)");
- textureprocessingmempool = Mem_AllocPool("Texture Processing Buffers");
+ texturemempool = Mem_AllocPool("Texture Info", 0, NULL);
+ texturedatamempool = Mem_AllocPool("Texture Storage (not yet uploaded)", 0, NULL);
+ textureprocessingmempool = Mem_AllocPool("Texture Processing Buffers", 0, NULL);
// Disable JPEG screenshots if the DLL isn't loaded
if (! JPEG_OpenLibrary ())
Cvar_SetValueQuick(&deathmatch, 1);
svs.maxclients = numplayers;
- sv_clients_mempool = Mem_AllocPool("server clients");
+ sv_clients_mempool = Mem_AllocPool("server clients", 0, NULL);
svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
}
Mem_Free(resamplerow1);
resamplerowsize = outwidth*4;
if (!resamplemempool)
- resamplemempool = Mem_AllocPool("Image Scaling Buffer");
+ resamplemempool = Mem_AllocPool("Image Scaling Buffer", 0, NULL);
resamplerow1 = Mem_Alloc(resamplemempool, resamplerowsize*2);
resamplerow2 = resamplerow1 + resamplerowsize;
}
void M_Init (void)
{
- menu_mempool = Mem_AllocPool("Menu");
+ menu_mempool = Mem_AllocPool("Menu", 0, NULL);
menuplyr_load = true;
menuplyr_pixels = NULL;
prog->error_cmd = MP_Error;
// allocate the mempools
- prog->edicts_mempool = Mem_AllocPool(M_NAME " edicts mempool");
- prog->edictstring_mempool = Mem_AllocPool( M_NAME " edict string mempool");
- prog->progs_mempool = Mem_AllocPool(M_PROG_FILENAME);
+ prog->edicts_mempool = Mem_AllocPool(M_NAME " edicts mempool", 0, NULL);
+ prog->edictstring_mempool = Mem_AllocPool( M_NAME " edict string mempool", 0, NULL);
+ prog->progs_mempool = Mem_AllocPool(M_PROG_FILENAME, 0, NULL);
PRVM_LoadProgs(M_PROG_FILENAME, m_numrequiredfunc, m_required_func);
Cvar_RegisterVariable(&r_meshqueue_immediaterender);
Cvar_RegisterVariable(&r_meshqueue_sort);
- meshqueuemempool = Mem_AllocPool("R_MeshQueue");
+ meshqueuemempool = Mem_AllocPool("R_MeshQueue", 0, NULL);
mq_total = 0;
mqt_total = 1000;
mq_array = NULL;
VectorSet(mod->rotatedmaxs, mod->radius, mod->radius, mod->radius);
// all models use memory, so allocate a memory pool
- mod->mempool = Mem_AllocPool(mod->name);
+ mod->mempool = Mem_AllocPool(mod->name, 0, NULL);
// all models load textures, so allocate a texture pool
if (cls.state != ca_dedicated)
mod->texturepool = R_AllocTexturePool();
{
int i;
lhnetaddress_t tempaddress;
- netconn_mempool = Mem_AllocPool("Networking");
+ netconn_mempool = Mem_AllocPool("Networking", 0, NULL);
Cmd_AddCommand("net_stats", Net_Stats_f);
Cmd_AddCommand("net_slist", Net_Slist_f);
Cmd_AddCommand("heartbeat", Net_Heartbeat_f);
void PR_Cmd_Init(void)
{
- pr_strings_mempool = Mem_AllocPool("pr_stringszone");
+ pr_strings_mempool = Mem_AllocPool("pr_stringszone", 0, NULL);
PR_Files_Init();
PR_Search_Init();
}
Cvar_RegisterVariable (&pr_boundscheck);
Cvar_RegisterVariable (&pr_traceqc);
- progs_mempool = Mem_AllocPool("progs.dat");
- edictstring_mempool = Mem_AllocPool("edict strings");
+ progs_mempool = Mem_AllocPool("progs.dat", 0, NULL);
+ edictstring_mempool = Mem_AllocPool("edict strings", 0, NULL);
PR_Cmd_Init();
}
void VM_Cmd_Init(void)
{
// only init the stuff for the current prog
- VM_STRINGS_MEMPOOL = Mem_AllocPool(va("vm_stringsmempool[%s]",PRVM_NAME));
+ VM_STRINGS_MEMPOOL = Mem_AllocPool(va("vm_stringsmempool[%s]",PRVM_NAME), 0, NULL);
VM_Files_Init();
VM_Search_Init();
}
}
Cmd_AddCommand("r_shadow_help", R_Shadow_Help_f);
R_Shadow_EditLights_Init();
- r_shadow_mempool = Mem_AllocPool("R_Shadow");
+ r_shadow_mempool = Mem_AllocPool("R_Shadow", 0, NULL);
r_shadow_worldlightchain = NULL;
maxshadowelements = 0;
shadowelements = NULL;
if (COM_CheckParm("-nosound") || COM_CheckParm("-safe"))
return;
- snd_mempool = Mem_AllocPool("sound");
+ snd_mempool = Mem_AllocPool("sound", 0, NULL);
if (COM_CheckParm("-simsound"))
fakedma = true;
return false;
Mem_FreePool (&s->mempool);
- s->mempool = Mem_AllocPool (s->name);
+ s->mempool = Mem_AllocPool (s->name, 0, NULL);
// Load the file
data = FS_LoadFile (filename, s->mempool, false);
sfxbuffer_t* sb;
Mem_FreePool (&s->mempool);
- s->mempool = Mem_AllocPool(s->name);
+ s->mempool = Mem_AllocPool(s->name, 0, NULL);
// Load the file
data = FS_LoadFile(filename, s->mempool, false);
for (i = 0;i < MAX_MODELS;i++)
sprintf (localmodels[i], "*%i", i);
- sv_edicts_mempool = Mem_AllocPool("server edicts");
+ sv_edicts_mempool = Mem_AllocPool("server edicts", 0, NULL);
}
static void SV_SaveEntFile_f(void)
void UI_Init(void)
{
- ui_mem = Mem_AllocPool("Intern UI Memory");
+ ui_mem = Mem_AllocPool("Intern UI Memory", 0, NULL);
}
#define UI_Alloc(size) Mem_Alloc(ui_mem, size)
Con_Print("gfx.wad doesn't have WAD2 id\n");
else
{
- wad_mempool = Mem_AllocPool("gfx.wad");
+ wad_mempool = Mem_AllocPool("gfx.wad", 0, NULL);
wad_base = Mem_Alloc(wad_mempool, fs_filesize);
memcpy(wad_base, temp, fs_filesize);
#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);
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;
}
//#define MEMCLUMPING
#define POOLNAMESIZE 128
+// if set this pool will be printed in memlist reports
+#define POOLFLAG_TEMP 1
#if MEMCLUMPING
// give malloc padding so we can't waste most of a page at the end
#define MEMCLUMPSIZE (65536 - 1536)
// chain of clumps (if any)
struct memclump_s *clumpchain;
#endif
+ // POOLFLAG_*
+ int flags;
// total memory allocated in this pool (inside memheaders)
int totalsize;
// total memory allocated in this pool (actual malloc total)
#define Mem_Free(mem) _Mem_Free(mem, __FILE__, __LINE__)
#define Mem_CheckSentinels(data) _Mem_CheckSentinels(data, __FILE__, __LINE__)
#define Mem_CheckSentinelsGlobal() _Mem_CheckSentinelsGlobal(__FILE__, __LINE__)
-#define Mem_AllocPool(name) _Mem_AllocPool(name, NULL, __FILE__, __LINE__)
-#define Mem_AllocNestedPool(name, parent) _Mem_AllocPool(name, (parent), __FILE__, __LINE__)
+#define Mem_AllocPool(name, flags, parent) _Mem_AllocPool(name, flags, parent, __FILE__, __LINE__)
#define Mem_FreePool(pool) _Mem_FreePool(pool, __FILE__, __LINE__)
#define Mem_EmptyPool(pool) _Mem_EmptyPool(pool, __FILE__, __LINE__)
void *_Mem_Alloc(mempool_t *pool, int size, const char *filename, int fileline);
void _Mem_Free(void *data, const char *filename, int fileline);
-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);
void _Mem_FreePool(mempool_t **pool, const char *filename, int fileline);
void _Mem_EmptyPool(mempool_t *pool, const char *filename, int fileline);
void _Mem_CheckSentinels(void *data, const char *filename, int fileline);