UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mem.h File Reference

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

#include "../shared/cxx.h"

Go to the source code of this file.

Macros

#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_AllocTypeN(type, n)   static_cast<type*>(Mem_Alloc(sizeof(type) * (n)))
 
#define Mem_AllocType(type)   static_cast<type*>(Mem_Alloc(sizeof(type)))
 
#define Mem_Alloc(size)   Mem_PoolAlloc((size), com_genericPool, 0)
 
#define Mem_PoolAlloc(size, pool, tagNum)   _Mem_Alloc((size),true,(pool),(tagNum),__FILE__,__LINE__)
 
#define Mem_PoolAllocTypeN(type, n, pool)   static_cast<type*>(Mem_PoolAlloc(sizeof(type) * (n), (pool), 0))
 
#define Mem_PoolAllocType(type, pool)   static_cast<type*>(Mem_PoolAllocTypeN(type, 1, (pool)))
 
#define Mem_ReAlloc(ptr, size)   _Mem_ReAlloc((ptr),(size),__FILE__,__LINE__)
 
#define Mem_SafeReAlloc(ptr, size)   ((ptr) ? Mem_ReAlloc(ptr, size) : Mem_Alloc(size))
 
#define Mem_Dup(type, in, n)   static_cast<type*>(_Mem_PoolDup(1 ? (in) : static_cast<type*>(0) /* type check */, sizeof(type) * (n), 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_ChangeTag(pool, tagFrom, tagTo)   _Mem_ChangeTag((pool),(tagFrom),(tagTo))
 
#define Mem_CheckGlobalIntegrity()   _Mem_CheckGlobalIntegrity(__FILE__,__LINE__)
 

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. More...
 
void _Mem_FreePool (memPool_t *pool, const char *fileName, const int fileLine)
 Free all items within a pool. More...
 
void_Mem_Alloc (size_t size, bool 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. More...
 
void_Mem_ReAlloc (void *ptr, size_t size, 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. More...
 
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. More...
 
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

#define Mem_Alloc (   size)    Mem_PoolAlloc((size), com_genericPool, 0)

Definition at line 40 of file mem.h.

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

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

Definition at line 52 of file mem.h.

Referenced by R_SwitchModelMemPoolTag().

#define Mem_CheckGlobalIntegrity ( )    _Mem_CheckGlobalIntegrity(__FILE__,__LINE__)

Definition at line 54 of file mem.h.

Referenced by Qcommon_Init().

#define Mem_DeletePool (   pool)    _Mem_DeletePool((pool),__FILE__,__LINE__)
#define Mem_Dup (   type,
  in,
 
)    static_cast<type*>(_Mem_PoolDup(1 ? (in) : static_cast<type*>(0) /* type check */, sizeof(type) * (n), com_genericPool, 0, __FILE__, __LINE__))
#define Mem_Free (   ptr)    _Mem_Free((ptr),__FILE__,__LINE__)

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(), 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(), SL_SliceTheWorld(), 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().

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

Definition at line 36 of file mem.h.

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

#define Mem_PoolAlloc (   size,
  pool,
  tagNum 
)    _Mem_Alloc((size),true,(pool),(tagNum),__FILE__,__LINE__)
#define Mem_PoolAllocTypeN (   type,
  n,
  pool 
)    static_cast<type*>(Mem_PoolAlloc(sizeof(type) * (n), (pool), 0))
#define Mem_PoolSize (   pool)    _Mem_PoolSize((pool))

Definition at line 51 of file mem.h.

Referenced by SV_ShutdownGameProgs().

#define Mem_PoolStrDupTo (   in,
  out,
  pool,
  tagNum 
)    _Mem_PoolStrDupTo((in),(out),(pool),(tagNum),__FILE__,__LINE__)

Definition at line 49 of file mem.h.

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

#define Mem_ReAlloc (   ptr,
  size 
)    _Mem_ReAlloc((ptr),(size),__FILE__,__LINE__)

Definition at line 44 of file mem.h.

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

#define Mem_SafeReAlloc (   ptr,
  size 
)    ((ptr) ? Mem_ReAlloc(ptr, size) : Mem_Alloc(size))

Definition at line 45 of file mem.h.

Referenced by R_ReallocateStateArrays(), and R_ReallocateTexunitArray().

Function Documentation

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 482 of file mem.cpp.

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

Referenced by UI_FreeStringProperty(), and UI_ResetData().

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

Definition at line 422 of file mem.cpp.

References memPool_t::blocks, MEM_HASH, and memBlock_t::next.

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

Definition at line 466 of file mem.cpp.

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

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_FreePool(), memPool_t::inUse, and memPool_t::name.

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 260 of file mem.cpp.

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

Referenced by _Mem_DeletePool().

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 241 of file mem.cpp.

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

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 385 of file mem.cpp.

References _Mem_Alloc().

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

Definition at line 414 of file mem.cpp.

References memPool_t::byteCount.

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 403 of file mem.cpp.

References _Mem_Alloc().

Referenced by _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 377 of file mem.cpp.

References _Mem_PoolStrDup().

void* _Mem_ReAlloc ( void ptr,
size_t  size,
const char *  fileName,
const int  fileLine 
)
void Mem_Init ( void  )
See also
Qcommon_Init
Mem_Shutdown

Definition at line 588 of file mem.cpp.

References Cmd_AddCommand(), and z_lock.

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

void Mem_Shutdown ( void  )