mem.h File Reference

Memory handling with sentinel checking and pools with tags for grouped free'ing. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  memBlockFoot_s
struct  memBlock_s
struct  memPool_s

Defines

#define MEM_MAX_POOLNAME   64
#define MEM_HASH   11
#define Mem_CreatePool(name)   _Mem_CreatePool((name),__FILE__,__LINE__)
#define Mem_DeletePool(pool)   _Mem_DeletePool((pool),__FILE__,__LINE__)
#define Mem_Free(ptr)   _Mem_Free((ptr),__FILE__,__LINE__)
#define Mem_FreeTag(pool, tagNum)   _Mem_FreeTag((pool),(tagNum),__FILE__,__LINE__)
#define Mem_FreePool(pool)   _Mem_FreePool((pool),__FILE__,__LINE__)
#define Mem_Alloc(size)   _Mem_Alloc((size),qtrue,com_genericPool,0,__FILE__,__LINE__)
#define Mem_AllocExt(size, zeroFill)   _Mem_Alloc((size),(zeroFill),com_genericPool,0,__FILE__,__LINE__)
#define Mem_PoolAlloc(size, pool, tagNum)   _Mem_Alloc((size),qtrue,(pool),(tagNum),__FILE__,__LINE__)
#define Mem_PoolAllocExt(size, zeroFill, pool, tagNum)   _Mem_Alloc((size),(zeroFill),(pool),(tagNum),__FILE__,__LINE__)
#define Mem_ReAlloc(ptr, size)   _Mem_ReAlloc((ptr),(size),__FILE__,__LINE__)
#define Mem_Dup(in, size)   _Mem_PoolDup((in),(size),com_genericPool,0,__FILE__,__LINE__)
#define Mem_StrDup(in)   _Mem_PoolStrDup((in),com_genericPool,0,__FILE__,__LINE__)
#define Mem_PoolStrDupTo(in, out, pool, tagNum)   _Mem_PoolStrDupTo((in),(out),(pool),(tagNum),__FILE__,__LINE__)
#define Mem_PoolStrDup(in, pool, tagNum)   _Mem_PoolStrDup((in),(pool),(tagNum),__FILE__,__LINE__)
#define Mem_PoolSize(pool)   _Mem_PoolSize((pool))
#define Mem_TagSize(pool, tagNum)   _Mem_TagSize((pool),(tagNum))
#define Mem_ChangeTag(pool, tagFrom, tagTo)   _Mem_ChangeTag((pool),(tagFrom),(tagTo))
#define Mem_CheckPoolIntegrity(pool)   _Mem_CheckPoolIntegrity((pool),__FILE__,__LINE__)
#define Mem_CheckGlobalIntegrity()   _Mem_CheckGlobalIntegrity(__FILE__,__LINE__)
#define Mem_TouchPool(pool)   _Mem_TouchPool((pool),__FILE__,__LINE__)
#define Mem_TouchGlobal()   _Mem_TouchGlobal(__FILE__,__LINE__)

Typedefs

typedef struct memBlockFoot_s memBlockFoot_t
typedef struct memBlock_s memBlock_t
typedef struct memPool_s memPool_t

Functions

memPool_t_Mem_CreatePool (const char *name, const char *fileName, const int fileLine) __attribute__((malloc))
uint32_t _Mem_DeletePool (memPool_t *pool, const char *fileName, const int fileLine)
uint32_t _Mem_Free (void *ptr, const char *fileName, const int fileLine)
uint32_t _Mem_FreeTag (memPool_t *pool, const int tagNum, const char *fileName, const int fileLine)
 Free memory blocks assigned to a specified tag within a pool.
uint32_t _Mem_FreePool (memPool_t *pool, const char *fileName, const int fileLine)
 Free all items within a pool.
void * _Mem_Alloc (size_t size, qboolean zeroFill, memPool_t *pool, const int tagNum, const char *fileName, const int fileLine) __attribute__((malloc))
 Optionally returns 0 filled memory allocated in a pool with a tag.
void * _Mem_ReAlloc (void *ptr, size_t size, const char *fileName, const int fileLine)
size_t Mem_Size (const void *ptr)
char * _Mem_PoolStrDupTo (const char *in, char **out, memPool_t *pool, const int tagNum, const char *fileName, const int fileLine)
 Saves a string to client hunk.
void * _Mem_PoolDup (const void *in, size_t size, memPool_t *pool, const int tagNum, const char *fileName, const int fileLine)
char * _Mem_PoolStrDup (const char *in, memPool_t *pool, const int tagNum, const char *fileName, const int fileLine) __attribute__((malloc))
 No need to null terminate the extra spot because Mem_Alloc returns zero-filled memory.
uint32_t _Mem_PoolSize (memPool_t *pool)
uint32_t _Mem_TagSize (memPool_t *pool, const int tagNum)
uint32_t _Mem_ChangeTag (memPool_t *pool, const int tagFrom, const int tagTo)
void _Mem_CheckPoolIntegrity (memPool_t *pool, const char *fileName, const int fileLine)
void _Mem_CheckGlobalIntegrity (const char *fileName, const int fileLine)
void _Mem_TouchPool (memPool_t *pool, const char *fileName, const int fileLine)
void _Mem_TouchGlobal (const char *fileName, const int fileLine)
void * _Mem_AllocatedInPool (memPool_t *pool, const void *pointer)
void Mem_Init (void)
uint32_t Mem_Shutdown (void)

Detailed Description

Memory handling with sentinel checking and pools with tags for grouped free'ing.

Definition in file mem.h.


Define Documentation

#define Mem_Alloc ( size   )     _Mem_Alloc((size),qtrue,com_genericPool,0,__FILE__,__LINE__)
#define Mem_AllocExt ( size,
zeroFill   )     _Mem_Alloc((size),(zeroFill),com_genericPool,0,__FILE__,__LINE__)

Definition at line 77 of file mem.h.

#define Mem_ChangeTag ( pool,
tagFrom,
tagTo   )     _Mem_ChangeTag((pool),(tagFrom),(tagTo))

Definition at line 88 of file mem.h.

Referenced by R_SwitchModelMemPoolTag().

 
#define Mem_CheckGlobalIntegrity (  )     _Mem_CheckGlobalIntegrity(__FILE__,__LINE__)

Definition at line 91 of file mem.h.

Referenced by Qcommon_Init().

#define Mem_CheckPoolIntegrity ( pool   )     _Mem_CheckPoolIntegrity((pool),__FILE__,__LINE__)

Definition at line 90 of file mem.h.

#define Mem_CreatePool ( name   )     _Mem_CreatePool((name),__FILE__,__LINE__)
#define Mem_DeletePool ( pool   )     _Mem_DeletePool((pool),__FILE__,__LINE__)

Definition at line 71 of file mem.h.

Referenced by Mem_Shutdown(), and SV_ShutdownGameProgs().

#define Mem_Dup ( in,
size   )     _Mem_PoolDup((in),(size),com_genericPool,0,__FILE__,__LINE__)

Definition at line 82 of file mem.h.

Referenced by MD2GLCmdsRemove(), and MD2SkinFix().

#define Mem_Free ( ptr   )     _Mem_Free((ptr),__FILE__,__LINE__)

Definition at line 73 of file mem.h.

Referenced by AIR_PostLoadInitMissions(), ASE_FreeGeomObject(), BuildFacelights(), Cbuf_AddLateCommands(), Cbuf_InsertText(), Check_Free(), Check_InitEntityDefs(), Check_SidesOverlap(), Check_Stats(), CIN_OGM_StopCinematic(), CIN_ROQ_PlayCinematic(), CIN_ROQ_StopCinematic(), CL_ActorCleanup(), CL_ExecuteBattlescapeEvent(), CL_FilterEventQueue(), CL_FreeBattlescapeEvent(), CL_HTTP_Cleanup(), CL_ParseFileList(), CL_PingServers_f(), CL_QueryMasterServerThread(), CL_SetHTTPServer(), CloseTracingNodes(), Cmd_Alias_f(), Cmd_BufClear(), Cmd_Exec_f(), Cmd_RemoveCommand(), Com_UnregisterConstVariable(), CP_CreateBattleParameters(), Cvar_Delete(), Cvar_FixCheatVars(), Cvar_FullSet(), Cvar_Get(), Cvar_Set2(), Cvar_UnRegisterChangeListener(), EndOfScript(), free_dbuffer(), free_element(), FreeBrush(), FreeFace(), FreeInventory(), FreePatches(), FreePortal(), FreeTree(), FreeTree_r(), FreeWinding(), FS_AddGameDirectory(), FS_BuildFileList(), FS_CopyFile(), FS_GetMaps(), FS_Shutdown(), GAME_FreeInventory(), HTTP_Recv(), Irc_Client_CmdRplNamreply(), Irc_Logic_RemoveChannelName(), Irc_Proto_Disconnect(), Irc_Proto_DrainBucket(), Key_SetBinding(), LIST_Delete(), LIST_RemoveEntry(), LoadJPG(), MAP_Init(), Master_HeartbeatThread(), Master_Shutdown(), MD2GLCmdsRemove(), MD2SkinFix(), MoveBrushesToWorld(), MP_LoadTeamMultiplayer(), MP_SaveTeamMultiplayer(), NET_DatagramSocketClose(), NET_StreamClose(), NET_Wait(), Qcommon_Frame(), R_BuildLightmap(), R_DeleteFBObject(), R_ImageClearMaterials(), R_LoadMaterials(), R_LoadObjModel(), R_LoadShader(), R_ModCalcUniqueNormalsAndTangents(), R_ModelLoadDPMVertsForFrame(), R_ModLoadAliasMD2MeshIndexed(), R_ModLoadAliasMD2MeshUnindexed(), R_ModReloadSurfacesArrays(), R_PreprocessShader(), R_ScreenShot(), R_ShutdownFBObjects(), R_SoftenTexture(), R_SortSurfacesArrays(), R_UploadData(), R_UploadTexture(), S_FreeSamples(), SAV_GameLoad(), SAV_GameSave(), SEQ_ExecuteRemove(), SetKeyValue(), SV_AssembleMap(), SV_Map(), SV_MapcycleClear(), SV_ParallelSearch(), SV_SetMaster_f(), SV_Shutdown(), testAssembly(), testMassAssemblyParallel(), testMassAssemblySequential(), testMassAssemblyTimeout(), TryLoadJPG(), TryLoadPNG(), TryLoadTGA(), UI_AbstractValueDelete(), UI_CloneCvarOrFloat(), UI_DrawModelNode(), UI_FreeRadarImages(), UI_FreeStringProperty(), UI_MaterialEditorRemoveStage_f(), UI_ModelNodeDelete(), UI_PopupList(), UI_RemoveListener(), UI_SetOneButton(), UI_Shutdown(), UI_TextNodeGenerateLineSplit(), WriteMapFile(), and WriteTGA24().

#define Mem_FreePool ( pool   )     _Mem_FreePool((pool),__FILE__,__LINE__)
#define Mem_FreeTag ( pool,
tagNum   )     _Mem_FreeTag((pool),(tagNum),__FILE__,__LINE__)

Definition at line 74 of file mem.h.

Referenced by FreeAllInventory(), GAME_FreeAllInventory(), R_ShutdownModels(), and S_Shutdown().

#define MEM_HASH   11
#define MEM_MAX_POOLNAME   64

Definition at line 29 of file mem.h.

Referenced by _Mem_CreatePool().

#define Mem_PoolAlloc ( size,
pool,
tagNum   )     _Mem_Alloc((size),qtrue,(pool),(tagNum),__FILE__,__LINE__)

Definition at line 78 of file mem.h.

Referenced by allocate_element(), AllocInventoryMemory(), CIN_OGM_PlayCinematic(), CIN_ROQ_DecodeInfo(), CIN_ROQ_PlayCinematic(), CL_ActorAddToTeamList(), CL_GetEventMail(), CL_ParseEvent(), CL_ParseLanguages(), CL_ParseTipsOfTheDay(), CM_MakeTracingNodes(), Cmd_AddCommand(), Cmd_Alias_f(), CMod_LoadBrushes(), CMod_LoadBrushSides(), CMod_LoadLeafBrushes(), CMod_LoadLeafs(), CMod_LoadLighting(), CMod_LoadNodes(), CMod_LoadPlanes(), CMod_LoadSubmodels(), CMod_LoadSurfaces(), Com_ParseTerrain(), Com_RegisterConstInt(), Cvar_Get(), Cvar_GetChangeListener(), FS_AddGameDirectory(), FS_BuildFileList(), FS_CopyFile(), FS_GetMaps(), FS_ListFiles(), FS_LoadPackFile(), GAME_AllocInventoryMemory(), Irc_Client_CmdRplNamreply(), Irc_Logic_AddChannelName(), LIST_Add(), LIST_AddPointer(), LIST_AddString(), LoadModel(), main(), MP_LoadTeamMultiplayer(), MP_SaveTeamMultiplayer(), MS_AddNewMessageSound(), NET_DatagramSend(), NET_DatagramSocketDoNew(), NET_StreamNew(), new_dbuffer(), R_BeginBuildingLightmaps(), R_BuildLightmap(), R_CreateSurfaceFlare(), R_LoadBspVertexArrays(), R_LoadImage(), R_LoadImageData(), R_LoadMaterials(), R_LoadObjModel(), R_LoadObjModelVertexArrays(), R_LoadObjSkin(), R_LoadShader(), R_LoadSurfacesArrays_(), R_ModCalcUniqueNormalsAndTangents(), R_ModelLoadDPMVertsForFrame(), R_ModLoadAliasDPMModel(), R_ModLoadAliasMD2Mesh(), R_ModLoadAliasMD2MeshIndexed(), R_ModLoadAliasMD2MeshUnindexed(), R_ModLoadAliasMD3Model(), R_ModLoadAnims(), R_ModLoadArrayData(), R_ModLoadEdges(), R_ModLoadLeafs(), R_ModLoadLighting(), R_ModLoadMDX(), R_ModLoadNodes(), R_ModLoadPlanes(), R_ModLoadSubmodels(), R_ModLoadSurfaces(), R_ModLoadSurfedges(), R_ModLoadTags(), R_ModLoadTexinfo(), R_ModLoadVertexes(), R_PreprocessShader(), R_ScreenShot(), R_SortSurfacesArrays(), R_SphereGenerate(), S_LoadSample(), SAV_GameLoad(), SAV_GameSave(), Schedule_Event(), Schedule_Timer(), SV_InitGame(), SV_MapcycleAdd(), UI_AbstractValueNew(), UI_AddListener(), UI_AllocNodeWithoutNew(), UI_DrawModelNode(), UI_Init(), UI_MaterialEditorNewStage_f(), UI_ModelNodeNew(), UI_PoolAllocAction(), and UI_WindowNodeAddIndexedNode().

#define Mem_PoolAllocExt ( size,
zeroFill,
pool,
tagNum   )     _Mem_Alloc((size),(zeroFill),(pool),(tagNum),__FILE__,__LINE__)

Definition at line 79 of file mem.h.

Referenced by R_SoftenTexture(), R_UploadData(), and R_UploadTexture().

#define Mem_PoolSize ( pool   )     _Mem_PoolSize((pool))

Definition at line 86 of file mem.h.

Referenced by SV_ShutdownGameProgs().

#define Mem_PoolStrDup ( in,
pool,
tagNum   )     _Mem_PoolStrDup((in),(pool),(tagNum),__FILE__,__LINE__)
#define Mem_PoolStrDupTo ( in,
out,
pool,
tagNum   )     _Mem_PoolStrDupTo((in),(out),(pool),(tagNum),__FILE__,__LINE__)
#define Mem_ReAlloc ( ptr,
size   )     _Mem_ReAlloc((ptr),(size),__FILE__,__LINE__)

Definition at line 80 of file mem.h.

Referenced by R_ModLoadAliasMD2Mesh().

#define Mem_StrDup ( in   )     _Mem_PoolStrDup((in),com_genericPool,0,__FILE__,__LINE__)
#define Mem_TagSize ( pool,
tagNum   )     _Mem_TagSize((pool),(tagNum))

Definition at line 87 of file mem.h.

 
#define Mem_TouchGlobal (  )     _Mem_TouchGlobal(__FILE__,__LINE__)

Definition at line 94 of file mem.h.

Referenced by CL_Init(), and Qcommon_Init().

#define Mem_TouchPool ( pool   )     _Mem_TouchPool((pool),__FILE__,__LINE__)

Definition at line 93 of file mem.h.


Typedef Documentation

typedef struct memBlock_s memBlock_t
typedef struct memPool_s memPool_t

Function Documentation

void* _Mem_Alloc ( size_t  size,
qboolean  zeroFill,
memPool_t pool,
const int  tagNum,
const char *  fileName,
const int  fileLine 
)
void* _Mem_AllocatedInPool ( struct memPool_s pool,
const void *  pointer 
)

Searches a given pointer in all memory pool blocks

Parameters:
pool The pool to search the pointer in
pointer The pointer to search in the pool

Definition at line 559 of file mem.c.

References memPool_s::blocks, MEM_HASH, memBlock_s::memPointer, and memBlock_s::next.

Referenced by UI_FreeStringProperty(), and UI_ResetData().

uint32_t _Mem_ChangeTag ( memPool_t pool,
const int  tagFrom,
const int  tagTo 
)

Definition at line 450 of file mem.c.

References memPool_s::blocks, MEM_HASH, memBlock_s::next, and memBlock_s::tagNum.

void _Mem_CheckGlobalIntegrity ( const char *  fileName,
const int  fileLine 
)

Definition at line 519 of file mem.c.

References _Mem_CheckPoolIntegrity(), i, memPool_s::inUse, and m_numPools.

void _Mem_CheckPoolIntegrity ( memPool_t pool,
const char *  fileName,
const int  fileLine 
)
memPool_t* _Mem_CreatePool ( const char *  name,
const char *  fileName,
const int  fileLine 
)
uint32_t _Mem_DeletePool ( struct memPool_s pool,
const char *  fileName,
const int  fileLine 
)
See also:
_Mem_CreatePool
_Mem_FreePool

Definition at line 112 of file mem.c.

References _Mem_FreePool(), memPool_s::inUse, memPool_s::name, and qfalse.

uint32_t _Mem_Free ( void *  ptr,
const char *  fileName,
const int  fileLine 
)
uint32_t _Mem_FreePool ( struct memPool_s pool,
const char *  fileName,
const int  fileLine 
)

Free all items within a pool.

See also:
_Mem_CreatePool
_Mem_DeletePool

Definition at line 236 of file mem.c.

References _Mem_Free(), memPool_s::blockCount, memPool_s::blocks, memPool_s::byteCount, MEM_HASH, memBlock_s::memPointer, memBlock_s::next, and next.

Referenced by _Mem_DeletePool().

uint32_t _Mem_FreeTag ( memPool_t pool,
const int  tagNum,
const char *  fileName,
const int  fileLine 
)

Free memory blocks assigned to a specified tag within a pool.

Definition at line 209 of file mem.c.

References _Mem_Free(), memPool_s::blocks, MEM_HASH, memBlock_s::memPointer, memBlock_s::next, next, and memBlock_s::tagNum.

Referenced by SV_FreeTags().

void* _Mem_PoolDup ( const void *  in,
size_t  size,
memPool_t pool,
const int  tagNum,
const char *  fileName,
const int  fileLine 
)

Definition at line 387 of file mem.c.

References _Mem_Alloc(), and qfalse.

uint32_t _Mem_PoolSize ( struct memPool_s pool  ) 
Parameters:
[in] pool The pool to get the size from

Definition at line 420 of file mem.c.

References memPool_s::byteCount.

char* _Mem_PoolStrDup ( const char *  in,
struct memPool_s pool,
const int  tagNum,
const char *  fileName,
const int  fileLine 
)

No need to null terminate the extra spot because Mem_Alloc returns zero-filled memory.

Parameters:
[in] in String to store in the given pool
[in] pool The pool to allocate the memory in
[in] tagNum 
[in] fileName The filename where this function was called from
[in] fileLine The line where this function was called from

Definition at line 407 of file mem.c.

References _Mem_Alloc(), and qtrue.

Referenced by _Mem_PoolStrDupTo().

char* _Mem_PoolStrDupTo ( const char *  in,
char **  out,
struct memPool_s pool,
const int  tagNum,
const char *  fileName,
const int  fileLine 
)

Saves a string to client hunk.

Parameters:
[in] in String to store in the given pool
[out] out The location where you want the pool pointer to be stored
[in] pool The pool to allocate the memory in
[in] tagNum 
[in] fileName The filename where this function was called from
[in] fileLine The line where this function was called from

Definition at line 379 of file mem.c.

References _Mem_PoolStrDup().

void* _Mem_ReAlloc ( void *  ptr,
size_t  size,
const char *  fileName,
const int  fileLine 
)
uint32_t _Mem_TagSize ( memPool_t pool,
const int  tagNum 
)

Definition at line 429 of file mem.c.

References memPool_s::blocks, MEM_HASH, memBlock_s::next, memBlock_s::size, and memBlock_s::tagNum.

void _Mem_TouchGlobal ( const char *  fileName,
const int  fileLine 
)

Definition at line 579 of file mem.c.

References _Mem_TouchPool(), i, memPool_s::inUse, and m_numPools.

void _Mem_TouchPool ( memPool_t pool,
const char *  fileName,
const int  fileLine 
)

Definition at line 531 of file mem.c.

References memPool_s::blocks, byte, i, MEM_HASH, memBlock_s::memPointer, memBlock_s::memSize, and memBlock_s::next.

Referenced by _Mem_TouchGlobal().

void Mem_Init ( void   ) 
See also:
Qcommon_Init
Mem_Shutdown

Definition at line 683 of file mem.c.

References Cmd_AddCommand(), and z_lock.

Referenced by main(), Qcommon_Init(), and TEST_Init().

uint32_t Mem_Shutdown ( void   ) 
size_t Mem_Size ( const void *  ptr  ) 
Parameters:
[in] ptr The ptr to get the allocated size from

Definition at line 364 of file mem.c.

References byte, and memBlock_s::size.


Generated by  doxygen 1.6.2