From: havoc Date: Wed, 25 Aug 2004 08:50:52 +0000 (+0000) Subject: Mem_AllocPool flags and parent parameters added, now there can be multiple temporary... X-Git-Tag: xonotic-v0.1.0preview~5700 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e13a8c596f2c51ca815773f89fee4f4f4f723f74;p=xonotic%2Fdarkplaces.git Mem_AllocPool flags and parent parameters added, now there can be multiple temporary mempools by using the POOLFLAG_TEMP option, and removed Mem_AllocNestedPool git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4377 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cgamevm.c b/cgamevm.c index 721c3392..31881975 100644 --- a/cgamevm.c +++ b/cgamevm.c @@ -23,7 +23,7 @@ static model_t *cgvm_model[MAX_CGVM_MODELS]; void CL_CGVM_Init(void) { - cgvm_mempool = Mem_AllocPool("CGVM"); + cgvm_mempool = Mem_AllocPool("CGVM", 0, NULL); } void CL_CGVM_Clear(void) diff --git a/cl_main.c b/cl_main.c index 8ab9bf73..21b125cb 100644 --- a/cl_main.c +++ b/cl_main.c @@ -1236,8 +1236,8 @@ CL_Init */ 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 diff --git a/cl_parse.c b/cl_parse.c index b7fe200e..fae79068 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -1820,7 +1820,7 @@ void CL_Parse_DumpPacket(void) 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); diff --git a/cl_particles.c b/cl_particles.c index 0fb500f6..6f905785 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -355,7 +355,7 @@ void CL_Particles_Init (void) #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; diff --git a/cl_video.c b/cl_video.c index 165f1b06..130a58ff 100644 --- a/cl_video.c +++ b/cl_video.c @@ -156,5 +156,5 @@ void CL_Video_Init(void) Cmd_AddCommand("playvideo", CL_PlayVideo_f); Cmd_AddCommand("stopvideo", CL_StopVideo_f); - clvideomempool = Mem_AllocPool("CL_Video"); + clvideomempool = Mem_AllocPool("CL_Video", 0, NULL); } diff --git a/cmd.c b/cmd.c index 2e134d78..10ee1366 100644 --- a/cmd.c +++ b/cmd.c @@ -462,7 +462,7 @@ Cmd_Init */ void Cmd_Init (void) { - cmd_mempool = Mem_AllocPool("commands"); + cmd_mempool = Mem_AllocPool("commands", 0, NULL); // // register our commands diff --git a/common.c b/common.c index 0d5c2a9f..dcc333b7 100644 --- a/common.c +++ b/common.c @@ -342,7 +342,7 @@ void SZ_Alloc (sizebuf_t *buf, int startsize, const char *name) { 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; diff --git a/console.c b/console.c index d72ddf6e..963d03db 100644 --- a/console.c +++ b/console.c @@ -419,7 +419,7 @@ Con_Init */ 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; diff --git a/fs.c b/fs.c index 9eb46843..d5072995 100644 --- a/fs.c +++ b/fs.c @@ -550,7 +550,7 @@ pack_t *FS_LoadPackPK3 (const char *packfile) 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; @@ -744,7 +744,7 @@ pack_t *FS_LoadPackPAK (const char *packfile) 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; @@ -886,8 +886,8 @@ void FS_Init (void) 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); diff --git a/gl_backend.c b/gl_backend.c index 90562380..7ba45451 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -149,7 +149,7 @@ static void R_Mesh_CacheArray_Shutdown(void); 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(); } diff --git a/gl_models.c b/gl_models.c index 223be1b8..fac269f9 100644 --- a/gl_models.c +++ b/gl_models.c @@ -61,7 +61,7 @@ void gl_models_freearrays(void) 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); } diff --git a/gl_textures.c b/gl_textures.c index 149ab888..0c9147ca 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -482,9 +482,9 @@ static void r_textures_start(void) // 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 ()) diff --git a/host.c b/host.c index 412f75e9..b1ed19b0 100644 --- a/host.c +++ b/host.c @@ -214,7 +214,7 @@ void Host_ServerOptions (void) 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); } diff --git a/image.c b/image.c index 8b150c40..3ecbea39 100644 --- a/image.c +++ b/image.c @@ -1307,7 +1307,7 @@ void Image_Resample (const void *indata, int inwidth, int inheight, int indepth, 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; } diff --git a/menu.c b/menu.c index 34ae9d32..ed3e79ce 100644 --- a/menu.c +++ b/menu.c @@ -3725,7 +3725,7 @@ void M_Shutdown(void); void M_Init (void) { - menu_mempool = Mem_AllocPool("Menu"); + menu_mempool = Mem_AllocPool("Menu", 0, NULL); menuplyr_load = true; menuplyr_pixels = NULL; @@ -4129,9 +4129,9 @@ void MP_Init (void) 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); diff --git a/meshqueue.c b/meshqueue.c index 52366e9c..6c9f1807 100644 --- a/meshqueue.c +++ b/meshqueue.c @@ -29,7 +29,7 @@ void R_MeshQueue_Init(void) 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; diff --git a/model_shared.c b/model_shared.c index 2d8601a1..17b6e284 100644 --- a/model_shared.c +++ b/model_shared.c @@ -297,7 +297,7 @@ static model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, 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(); diff --git a/netconn.c b/netconn.c index 12c97a2e..12636d4c 100755 --- a/netconn.c +++ b/netconn.c @@ -1593,7 +1593,7 @@ void NetConn_Init(void) { 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); diff --git a/pr_cmds.c b/pr_cmds.c index 0839455e..55ea9032 100644 --- a/pr_cmds.c +++ b/pr_cmds.c @@ -3422,7 +3422,7 @@ int pr_numbuiltins = sizeof(pr_builtin)/sizeof(pr_builtin[0]); 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(); } diff --git a/pr_edict.c b/pr_edict.c index 4643f3e4..bd3e3eca 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -1623,8 +1623,8 @@ void PR_Init (void) 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(); } diff --git a/prvm_cmds.c b/prvm_cmds.c index 6a7fc7d4..6b8abd75 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -2781,7 +2781,7 @@ void VM_getimagesize(void) 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(); } diff --git a/r_shadow.c b/r_shadow.c index ef1190c2..49d0701e 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -392,7 +392,7 @@ void R_Shadow_Init(void) } 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; diff --git a/snd_dma.c b/snd_dma.c index e3db4c90..5825fc62 100644 --- a/snd_dma.c +++ b/snd_dma.c @@ -215,7 +215,7 @@ void S_Init(void) 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; diff --git a/snd_ogg.c b/snd_ogg.c index 17fc7dff..ceab9efb 100644 --- a/snd_ogg.c +++ b/snd_ogg.c @@ -515,7 +515,7 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *s) 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); diff --git a/snd_wav.c b/snd_wav.c index a9440735..8d4f986b 100644 --- a/snd_wav.c +++ b/snd_wav.c @@ -241,7 +241,7 @@ qboolean S_LoadWavFile (const char *filename, sfx_t *s) 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); diff --git a/sv_main.c b/sv_main.c index 34622ddf..736cee1f 100644 --- a/sv_main.c +++ b/sv_main.c @@ -82,7 +82,7 @@ void SV_Init (void) 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) diff --git a/ui.c b/ui.c index 9915af56..0d1b67fd 100644 --- a/ui.c +++ b/ui.c @@ -49,7 +49,7 @@ static mempool_t *ui_mem; 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) diff --git a/wad.c b/wad.c index 44f39f31..ed96026d 100644 --- a/wad.c +++ b/wad.c @@ -79,7 +79,7 @@ void *W_GetLumpName(char *name) 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); diff --git a/zone.c b/zone.c index bde6fdf1..03a6bfa3 100644 --- a/zone.c +++ b/zone.c @@ -205,7 +205,7 @@ void _Mem_Free(void *data, const char *filename, int fileline) #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)); @@ -216,6 +216,7 @@ mempool_t *_Mem_AllocPool(const char *name, mempool_t *parent, const char *filen pool->sentinel2 = MEMHEADER_SENTINEL1; pool->filename = filename; pool->fileline = fileline; + pool->flags = flags; pool->chain = NULL; pool->totalsize = 0; pool->realsize = sizeof(mempool_t); @@ -348,14 +349,14 @@ void Mem_PrintStats(void) 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); + } } } @@ -368,10 +369,7 @@ void Mem_PrintList(int listallocations) "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) @@ -417,8 +415,8 @@ Memory_Init */ 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; } diff --git a/zone.h b/zone.h index f49f1471..f47561c2 100644 --- a/zone.h +++ b/zone.h @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //#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) @@ -93,6 +95,8 @@ typedef struct mempool_s // 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) @@ -117,14 +121,13 @@ mempool_t; #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);