Memory handling with sentinel checking and pools with tags for grouped free'ing. More...
#include "common.h"
#include <SDL_thread.h>
Go to the source code of this file.
Defines | |
#define | MEM_HEAD_SENTINEL_TOP 0xFEBDFAED |
#define | MEM_HEAD_SENTINEL_BOT 0xD0BAF0FF |
#define | MEM_FOOT_SENTINEL 0xF00DF00D |
#define | MEM_MAX_POOLCOUNT 32 |
Functions | |
static memPool_t * | Mem_FindPool (const char *name) |
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) |
static void | _Mem_CheckSentinels (void *ptr, const char *fileName, const int fileLine) |
uint32_t | _Mem_Free (void *ptr, const char *fileName, const int fileLine) |
uint32_t | _Mem_FreeTag (struct memPool_s *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 (struct memPool_s *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) |
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, struct memPool_s *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, struct memPool_s *pool, const int tagNum, const char *fileName, const int fileLine) |
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. | |
uint32_t | _Mem_PoolSize (struct memPool_s *pool) |
uint32_t | _Mem_TagSize (struct memPool_s *pool, const int tagNum) |
uint32_t | _Mem_ChangeTag (struct memPool_s *pool, const int tagFrom, const int tagTo) |
void | _Mem_CheckPoolIntegrity (struct memPool_s *pool, const char *fileName, const int fileLine) |
void | _Mem_CheckGlobalIntegrity (const char *fileName, const int fileLine) |
void | _Mem_TouchPool (struct memPool_s *pool, const char *fileName, const int fileLine) |
void * | _Mem_AllocatedInPool (struct memPool_s *pool, const void *pointer) |
void | _Mem_TouchGlobal (const char *fileName, const int fileLine) |
void | Mem_Init (void) |
uint32_t | Mem_Shutdown (void) |
Variables | |
static SDL_mutex * | z_lock |
static memPool_t | m_poolList [MEM_MAX_POOLCOUNT] |
static uint32_t | m_numPools |
Memory handling with sentinel checking and pools with tags for grouped free'ing.
Definition in file mem.c.
#define MEM_FOOT_SENTINEL 0xF00DF00D |
Definition at line 34 of file mem.c.
Referenced by _Mem_Alloc(), _Mem_CheckPoolIntegrity(), and _Mem_CheckSentinels().
#define MEM_HEAD_SENTINEL_BOT 0xD0BAF0FF |
Definition at line 33 of file mem.c.
Referenced by _Mem_Alloc(), _Mem_CheckPoolIntegrity(), and _Mem_CheckSentinels().
#define MEM_HEAD_SENTINEL_TOP 0xFEBDFAED |
Definition at line 32 of file mem.c.
Referenced by _Mem_Alloc(), _Mem_CheckPoolIntegrity(), and _Mem_CheckSentinels().
#define MEM_MAX_POOLCOUNT 32 |
Definition at line 38 of file mem.c.
Referenced by _Mem_CreatePool().
void* _Mem_Alloc | ( | size_t | size, | |
qboolean | zeroFill, | |||
memPool_t * | pool, | |||
const int | tagNum, | |||
const char * | fileName, | |||
const int | fileLine | |||
) |
Optionally returns 0 filled memory allocated in a pool with a tag.
Definition at line 262 of file mem.c.
References memBlock_s::allocFile, memBlock_s::allocLine, memPool_s::blockCount, memPool_s::blocks, memBlock_s::botSentinel, byte, memPool_s::byteCount, memBlock_s::footer, MEM_FOOT_SENTINEL, MEM_HASH, MEM_HEAD_SENTINEL_BOT, MEM_HEAD_SENTINEL_TOP, memBlock_s::memPointer, memBlock_s::memSize, memBlock_s::next, memBlock_s::pool, memBlockFoot_s::sentinel, memBlock_s::size, Sys_Error(), memBlock_s::tagNum, memBlock_s::topSentinel, UFO_SIZE_T, and z_lock.
Referenced by _Mem_PoolDup(), _Mem_PoolStrDup(), _Mem_ReAlloc(), FS_LoadFile(), and SV_TagAlloc().
void* _Mem_AllocatedInPool | ( | struct memPool_s * | pool, | |
const void * | pointer | |||
) |
Searches a given pointer in all memory pool blocks
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().
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 | ( | struct memPool_s * | pool, | |
const char * | fileName, | |||
const int | fileLine | |||
) |
Definition at line 474 of file mem.c.
References memBlock_s::allocFile, memBlock_s::allocLine, memPool_s::blockCount, memPool_s::blocks, memBlock_s::botSentinel, memPool_s::byteCount, memBlock_s::footer, MEM_FOOT_SENTINEL, MEM_HASH, MEM_HEAD_SENTINEL_BOT, MEM_HEAD_SENTINEL_TOP, memPool_s::name, memBlock_s::next, memBlock_s::pool, memBlockFoot_s::sentinel, memBlock_s::size, Sys_Error(), and memBlock_s::topSentinel.
Referenced by _Mem_CheckGlobalIntegrity().
static void _Mem_CheckSentinels | ( | void * | ptr, | |
const char * | fileName, | |||
const int | fileLine | |||
) | [static] |
Definition at line 134 of file mem.c.
References memBlock_s::allocFile, memBlock_s::allocLine, memBlock_s::botSentinel, byte, memBlock_s::footer, MEM_FOOT_SENTINEL, MEM_HEAD_SENTINEL_BOT, MEM_HEAD_SENTINEL_TOP, memPool_s::name, memBlock_s::pool, memBlockFoot_s::sentinel, Sys_Error(), and memBlock_s::topSentinel.
Referenced by _Mem_Free(), and _Mem_ReAlloc().
memPool_t* _Mem_CreatePool | ( | const char * | name, | |
const char * | fileName, | |||
const int | fileLine | |||
) |
Definition at line 67 of file mem.c.
References memPool_s::blockCount, memPool_s::blocks, memPool_s::byteCount, Com_Printf(), memPool_s::createFile, memPool_s::createLine, i, memPool_s::inUse, m_numPools, Mem_FindPool(), MEM_HASH, MEM_MAX_POOLCOUNT, MEM_MAX_POOLNAME, memPool_s::name, Q_strncpyz(), qtrue, and Sys_Error().
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 | |||
) |
Definition at line 164 of file mem.c.
References _Mem_CheckSentinels(), memPool_s::blockCount, memPool_s::blocks, byte, memPool_s::byteCount, MEM_HASH, memBlock_s::next, memBlock_s::pool, memBlock_s::size, and z_lock.
Referenced by _Mem_FreePool(), _Mem_FreeTag(), _Mem_ReAlloc(), FS_FreeFile(), and SV_MemFree().
Free all items within a pool.
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 | ( | struct memPool_s * | 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, | |||
struct memPool_s * | pool, | |||
const int | tagNum, | |||
const char * | fileName, | |||
const int | fileLine | |||
) |
Definition at line 387 of file mem.c.
References _Mem_Alloc(), and qfalse.
[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.
[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.
[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 | |||
) |
Definition at line 317 of file mem.c.
References _Mem_Alloc(), _Mem_CheckSentinels(), _Mem_Free(), byte, memBlock_s::memSize, memBlock_s::pool, qfalse, Sys_Error(), and memBlock_s::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 | ( | struct memPool_s * | 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().
static memPool_t* Mem_FindPool | ( | const char * | name | ) | [static] |
Definition at line 47 of file mem.c.
References i, memPool_s::inUse, m_numPools, and memPool_s::name.
Referenced by _Mem_CreatePool().
void Mem_Init | ( | void | ) |
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 | ) |
Definition at line 698 of file mem.c.
References memPool_s::inUse, Mem_DeletePool, and z_lock.
Referenced by Exit(), main(), Qcommon_Shutdown(), Sys_Error(), Sys_Quit(), and TEST_Shutdown().
size_t Mem_Size | ( | const void * | ptr | ) |
[in] | ptr | The ptr to get the allocated size from |
Definition at line 364 of file mem.c.
References byte, and memBlock_s::size.
uint32_t m_numPools [static] |
Definition at line 41 of file mem.c.
Referenced by _Mem_CheckGlobalIntegrity(), _Mem_CreatePool(), _Mem_TouchGlobal(), and Mem_FindPool().
memPool_t m_poolList[MEM_MAX_POOLCOUNT] [static] |
SDL_mutex* z_lock [static] |
Definition at line 36 of file mem.c.
Referenced by _Mem_Alloc(), _Mem_Free(), Mem_Init(), and Mem_Shutdown().