UFO: Alien Invasion
Loading...
Searching...
No Matches
mem.h File Reference

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

#include "../shared/cxx.h"
Include dependency graph for mem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define Mem_CreatePool(name)
#define Mem_DeletePool(pool)
#define Mem_Free(ptr)
#define Mem_FreeTag(pool, tagNum)
#define Mem_FreePool(pool)
#define Mem_AllocTypeN(type, n)
#define Mem_AllocType(type)
#define Mem_Alloc(size)
#define Mem_PoolAlloc(size, pool, tagNum)
#define Mem_PoolAllocTypeN(type, n, pool)
#define Mem_PoolAllocType(type, pool)
#define Mem_ReAlloc(ptr, size)
#define Mem_SafeReAlloc(ptr, size)
#define Mem_Dup(type, in, n)
#define Mem_StrDup(in)
#define Mem_PoolStrDupTo(in, out, pool, tagNum)
#define Mem_PoolStrDup(in, pool, tagNum)
#define Mem_PoolSize(pool)
#define Mem_ChangeTag(pool, tagFrom, tagTo)
#define Mem_CheckGlobalIntegrity()

Functions

memPool_t * _Mem_CreatePool (const char *name, const char *fileName, const int fileLine) __attribute__((malloc))
void _Mem_DeletePool (memPool_t *pool, const char *fileName, const int fileLine)
void _Mem_Free (void *ptr, const char *fileName, const int fileLine)
void _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.
void _Mem_FreePool (memPool_t *pool, const char *fileName, const int fileLine)
 Free all items within a pool.
void * _Mem_Alloc (size_t sizesize, bool zeroFill, memPool_t *pool, const int tagNum, const char *fileName, const int fileLine) __attribute__((malloc))
void * _Mem_ReAlloc (void *ptr, size_t sizesize, const char *fileName, const int fileLine)
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 sizesize, 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_ChangeTag (memPool_t *pool, const int tagFrom, const int tagTo)
void _Mem_CheckGlobalIntegrity (const char *fileName, const int fileLine)
bool _Mem_AllocatedInPool (memPool_t *pool, const void *pointer)
void Mem_Init (void)
void Mem_Shutdown (void)

Detailed Description

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

Definition in file mem.h.

Macro Definition Documentation

◆ Mem_Alloc

#define Mem_Alloc ( size)
Value:
memPool_t * com_genericPool
Definition common.cpp:72
voidpf void uLong size
Definition ioapi.h:42
#define Mem_PoolAlloc(size, pool, tagNum)
Definition mem.h:41

Definition at line 40 of file mem.h.

Referenced by _hash_alloc(), AllocBrush(), AllocWinding(), and CMod_LoadRouting().

◆ Mem_AllocType

◆ Mem_AllocTypeN

◆ Mem_ChangeTag

#define Mem_ChangeTag ( pool,
tagFrom,
tagTo )
Value:
_Mem_ChangeTag((pool),(tagFrom),(tagTo))
uint32_t _Mem_ChangeTag(memPool_t *pool, const int tagFrom, const int tagTo)
Definition mem.cpp:426

Definition at line 52 of file mem.h.

Referenced by R_SwitchModelMemPoolTag().

◆ Mem_CheckGlobalIntegrity

#define Mem_CheckGlobalIntegrity ( )
Value:
_Mem_CheckGlobalIntegrity(__FILE__,__LINE__)
void _Mem_CheckGlobalIntegrity(const char *fileName, const int fileLine)
Definition mem.cpp:470

Definition at line 54 of file mem.h.

Referenced by Qcommon_Init().

◆ Mem_CreatePool

◆ Mem_DeletePool

#define Mem_DeletePool ( pool)
Value:
_Mem_DeletePool((pool),__FILE__,__LINE__)
void _Mem_DeletePool(memPool_t *pool, const char *fileName, const int fileLine)
Definition mem.cpp:146

Definition at line 33 of file mem.h.

Referenced by CL_LanguageShutdown(), Irc_Shutdown(), Mem_Shutdown(), S_Shutdown(), SV_ShutdownGameProgs(), TEST_F(), and TEST_F().

◆ Mem_Dup

#define Mem_Dup ( type,
in,
n )
Value:
static_cast<type*>(_Mem_PoolDup(1 ? (in) : static_cast<type*>(0) , sizeof(type) * (n), com_genericPool, 0, __FILE__, __LINE__))
void * _Mem_PoolDup(const void *in, size_t size, memPool_t *pool, const int tagNum, const char *fileName, const int fileLine)
Definition mem.cpp:389

Definition at line 47 of file mem.h.

Referenced by MD2GLCmdsRemove(), MD2SkinEdit(), MD2SkinFix(), MD2SkinNum(), R_FontAnalyze(), and UI_ContainerNodeUpdateEquipment().

◆ Mem_Free

#define Mem_Free ( ptr)
Value:
_Mem_Free((ptr),__FILE__,__LINE__)
void _Mem_Free(void *ptr, const char *fileName, const int fileLine)
Definition mem.cpp:204

Definition at line 35 of file mem.h.

Referenced by _hash_free(), ASE_FreeGeomObject(), BuildFacelights(), Cbuf_AddLateCommands(), Cbuf_InsertText(), Check_Free(), Check_InitEntityDefs(), Check_SidesOverlap(), Check_Stats(), CIN_OGM_CloseCinematic(), CIN_ROQ_CloseCinematic(), CIN_ROQ_OpenCinematic(), CL_ExecuteBattlescapeEvent(), CL_FreeBattlescapeEvent(), CL_HTTP_Cleanup(), CL_ParseFileList(), CL_SetHTTPServer(), CloseTracingNodes(), Cmd_Alias_f(), Cmd_BufClear(), Cmd_Exec_f(), Cmd_RemoveCommand(), CMod_LoadRouting(), Com_AddObjectLinks(), Com_ParseFireEffect(), Com_ParseObjDefEffect(), Com_ParseTerrain(), Com_UnregisterConstVariable(), Cvar_Delete(), Cvar_FixCheatVars(), Cvar_FullSet(), Cvar_Get(), Cvar_Reset(), Cvar_Set2(), Cvar_UnRegisterChangeListener(), uiModelNode::deleteNode(), FreeBrush(), FreeFace(), FreeInventory(), FreeInventory(), FreePatches(), FreePortal(), FreeTree(), FreeTree_r(), FreeWinding(), FS_AddGameDirectory(), FS_BuildFileList(), FS_CopyFile(), FS_GetMaps(), FS_GetModList(), FS_Shutdown(), GAME_Free(), GAME_FreeInventory(), GAME_LoadTeam(), GAME_SaveTeam(), GetToken(), HTTP_GetURL(), HTTP_Recv(), Irc_Client_CmdRplNamreply(), Irc_Logic_RemoveChannelName(), Irc_Proto_Disconnect(), Irc_Proto_DrainBucket(), Key_SetBinding(), LET_StartIdle(), LIST_Delete(), LIST_RemoveEntry(), MD2GLCmdsRemove(), MD2SkinEdit(), MD2SkinFix(), MD2SkinNum(), MoveBrushesToWorld(), NET_DatagramSocketClose(), NET_StreamClose(), NET_Wait(), PQueueFree(), R_DeleteFBObject(), R_EndBuildingLightmaps(), R_FontShutdown(), R_ImageClearMaterials(), R_LoadMaterials(), R_LoadObjModel(), R_LoadShader(), R_ModCalcUniqueNormalsAndTangents(), R_ModLoadAliasMD2MeshIndexed(), R_ModLoadAliasMD2MeshUnindexed(), R_ModReloadSurfacesArrays(), R_PreprocessShaderR(), R_RenderToTexture(), R_ScreenShot(), R_ShutdownFBObjects(), R_SoftenTexture(), R_SortSurfacesArrays(), R_UploadData(), R_UploadTexture(), S_FreeSamples(), SEQ_ExecuteDelete(), SEQ_FreeContext(), STRHUNK_Delete(), SV_AssembleMap(), SV_AssembleMapAndTitle(), SV_DoMapAssemble(), SV_MapcycleClear(), SV_ParallelSearch(), SV_Shutdown(), TEST_F(), UI_ClearLineChart(), UI_CloneCvarOrFloat(), UI_ColumnLayout(), UI_ContainerNodeUpdateEquipment(), UI_DrawModelNode(), UI_ExecuteCallAction(), UI_FreeCvarOrFloat(), UI_FreeRadarImages(), UI_FreeStringProperty(), UI_InitializeNodeBehaviour(), UI_MaterialEditorRemoveStage_f(), UI_PopupList(), UI_RadioButton_SetValue(), UI_RemoveListener(), UI_SetOneButton(), UI_Shutdown(), UI_TextNodeGenerateLineSplit(), WriteMapFile(), and WriteTGA24().

◆ Mem_FreePool

#define Mem_FreePool ( pool)
Value:
_Mem_FreePool((pool),__FILE__,__LINE__)
void _Mem_FreePool(memPool_t *pool, const char *fileName, const int fileLine)
Free all items within a pool.
Definition mem.cpp:262

Definition at line 37 of file mem.h.

Referenced by CL_ParseMessageIDs(), CM_LoadMap(), Cmd_Shutdown(), FS_Shutdown(), GAME_FreePool(), R_ShutdownModels(), and UI_Shutdown().

◆ Mem_FreeTag

#define Mem_FreeTag ( pool,
tagNum )
Value:
_Mem_FreeTag((pool),(tagNum),__FILE__,__LINE__)
void _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 mem.cpp:243

Definition at line 36 of file mem.h.

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

◆ Mem_PoolAlloc

#define Mem_PoolAlloc ( size,
pool,
tagNum )
Value:
_Mem_Alloc((size),true,(pool),(tagNum),__FILE__,__LINE__)
void * _Mem_Alloc(size_t size, bool zeroFill, memPool_t *pool, const int tagNum, const char *fileName, const int fileLine)

Definition at line 41 of file mem.h.

Referenced by _hash_alloc(), AllocInventoryMemory(), AllocInventoryMemory(), GAME_AllocInventoryMemory(), R_ModLoadAliasMD2Mesh(), and UI_AllocNodeWithoutNew().

◆ Mem_PoolAllocType

◆ Mem_PoolAllocTypeN

#define Mem_PoolAllocTypeN ( type,
n,
pool )
Value:
static_cast<type*>(Mem_PoolAlloc(sizeof(type) * (n), (pool), 0))

Definition at line 42 of file mem.h.

Referenced by CIN_ROQ_DecodeInfo(), CL_ParseMessageIDs(), CL_ParseSequence(), CM_MakeTracingNodes(), CMod_LoadBrushes(), CMod_LoadBrushSides(), CMod_LoadLeafBrushes(), CMod_LoadLeafs(), CMod_LoadLighting(), CMod_LoadNodes(), CMod_LoadPlanes(), CMod_LoadSubmodels(), CMod_LoadSurfaces(), CP_UpdateNationXVIInfection(), FS_CopyFile(), FS_GetMaps(), FS_ListFiles(), FS_LoadFile(), FS_LoadPackFile(), GAME_LoadTeam(), GAME_SaveTeam(), uiModelNode::initNodeDynamic(), Irc_Client_CmdRplNamreply(), LIST_Add(), NET_DatagramSend(), R_BeginBuildingLightmaps(), R_BuildDefaultLightmap(), R_BuildLightmap(), R_LoadActorSkinsFromModel(), R_LoadBspVertexArrays(), R_LoadImage(), R_LoadObjModel(), R_LoadObjModelVertexArrays(), R_LoadObjSkin(), R_LoadShader(), R_LoadSurfacesArrays_(), R_ModCalcUniqueNormalsAndTangents(), 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_PreprocessShaderR(), R_RenderToTexture(), R_ScreenShot(), R_SoftenTexture(), R_SortSurfacesArrays(), R_SphereGenerate(), R_UploadData(), R_UploadTexture(), SAV_GameLoad(), SAV_GameSave(), SV_InitGame(), UI_AddLineChartLine(), UI_Init(), and UI_RegisterNodePropertyPosSize_().

◆ Mem_PoolSize

#define Mem_PoolSize ( pool)
Value:
uint32_t _Mem_PoolSize(memPool_t *pool)
Definition mem.cpp:418

Definition at line 51 of file mem.h.

Referenced by SV_ShutdownGameProgs().

◆ Mem_PoolStrDup

◆ Mem_PoolStrDupTo

#define Mem_PoolStrDupTo ( in,
out,
pool,
tagNum )
Value:
_Mem_PoolStrDupTo((in),(out),(pool),(tagNum),__FILE__,__LINE__)
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.
Definition mem.cpp:381

Definition at line 49 of file mem.h.

Referenced by Com_ParseBlockToken(), SEQ_ExecuteObj2D(), UI_ParseFont(), and UI_ParseUIModel().

◆ Mem_ReAlloc

#define Mem_ReAlloc ( ptr,
size )
Value:
_Mem_ReAlloc((ptr),(size),__FILE__,__LINE__)
void * _Mem_ReAlloc(void *ptr, size_t size, const char *fileName, const int fileLine)
Definition mem.cpp:333

Definition at line 44 of file mem.h.

Referenced by MD2SkinNum(), PQueuePush(), and R_ModLoadAliasMD2Mesh().

◆ Mem_SafeReAlloc

#define Mem_SafeReAlloc ( ptr,
size )
Value:
((ptr) ? Mem_ReAlloc(ptr, size) : Mem_Alloc(size))
#define Mem_ReAlloc(ptr, size)
Definition mem.h:44

Definition at line 45 of file mem.h.

Referenced by R_ReallocateStateArrays(), and R_ReallocateTexunitArray().

◆ Mem_StrDup

Function Documentation

◆ _Mem_Alloc()

◆ _Mem_AllocatedInPool()

bool _Mem_AllocatedInPool ( memPool_t * pool,
const void * pointer )

Searches a given pointer in all memory pool blocks

Parameters
poolThe pool to search the pointer in
pointerThe pointer to search in the pool

Definition at line 486 of file mem.cpp.

References _Mem_AllocatedInPool(), memPool_t::blocks, Mem_BlockToPtr(), MEM_HASH, memBlock_t::next, and pointer.

Referenced by _Mem_AllocatedInPool(), UI_FreeStringProperty(), and UI_ResetData().

◆ _Mem_ChangeTag()

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

Definition at line 426 of file mem.cpp.

References _Mem_ChangeTag(), memPool_t::blocks, MEM_HASH, and memBlock_t::next.

Referenced by _Mem_ChangeTag().

◆ _Mem_CheckGlobalIntegrity()

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

◆ _Mem_CreatePool()

◆ _Mem_DeletePool()

void _Mem_DeletePool ( memPool_t * pool,
const char * fileName,
const int fileLine )
See also
_Mem_CreatePool
_Mem_FreePool

Definition at line 146 of file mem.cpp.

References _Mem_DeletePool(), _Mem_FreePool(), memPool_t::inUse, and memPool_t::name.

Referenced by _Mem_DeletePool().

◆ _Mem_Free()

◆ _Mem_FreePool()

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

Free all items within a pool.

See also
_Mem_CreatePool
_Mem_DeletePool

Definition at line 262 of file mem.cpp.

References _Mem_Free(), _Mem_FreePool(), memPool_t::blockCount, memPool_t::blocks, memPool_t::byteCount, Mem_BlockToPtr(), and MEM_HASH.

Referenced by _Mem_DeletePool(), and _Mem_FreePool().

◆ _Mem_FreeTag()

void _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 243 of file mem.cpp.

References _Mem_Free(), _Mem_FreeTag(), memPool_t::blocks, Mem_BlockToPtr(), and MEM_HASH.

Referenced by _Mem_FreeTag(), and SV_FreeTags().

◆ _Mem_PoolDup()

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

Definition at line 389 of file mem.cpp.

References _Mem_Alloc(), and _Mem_PoolDup().

Referenced by _Mem_PoolDup().

◆ _Mem_PoolSize()

uint32_t _Mem_PoolSize ( memPool_t * pool)
Parameters
[in]poolThe pool to get the size from

Definition at line 418 of file mem.cpp.

References _Mem_PoolSize(), and memPool_t::byteCount.

Referenced by _Mem_PoolSize().

◆ _Mem_PoolStrDup()

char * _Mem_PoolStrDup ( const char * in,
memPool_t * 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]inString to store in the given pool
[in]poolThe pool to allocate the memory in
[in]tagNum
[in]fileNameThe filename where this function was called from
[in]fileLineThe line where this function was called from

Definition at line 407 of file mem.cpp.

References _Mem_Alloc(), and _Mem_PoolStrDup().

Referenced by _Mem_PoolStrDup(), and _Mem_PoolStrDupTo().

◆ _Mem_PoolStrDupTo()

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.

Parameters
[in]inString to store in the given pool
[out]outThe location where you want the pool pointer to be stored
[in]poolThe pool to allocate the memory in
[in]tagNum
[in]fileNameThe filename where this function was called from
[in]fileLineThe line where this function was called from

Definition at line 381 of file mem.cpp.

References _Mem_PoolStrDup(), and _Mem_PoolStrDupTo().

Referenced by _Mem_PoolStrDupTo().

◆ _Mem_ReAlloc()

void * _Mem_ReAlloc ( void * ptr,
size_t size,
const char * fileName,
const int fileLine )

◆ Mem_Init()

void Mem_Init ( void )
See also
Qcommon_Init
Mem_Shutdown

Definition at line 506 of file mem.cpp.

References Mem_Init(), Sys_Error(), and z_lock.

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

◆ Mem_Shutdown()