mem.c File Reference

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

#include "common.h"
#include <SDL_thread.h>
Include dependency graph for mem.c:

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_tMem_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

Detailed Description

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

Definition in file mem.c.


Define Documentation

#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().


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 ( struct memPool_s 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 ( struct memPool_s pool,
const char *  fileName,
const int  fileLine 
)
static void _Mem_CheckSentinels ( void *  ptr,
const char *  fileName,
const int  fileLine 
) [static]
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 ( 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.

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 ( struct memPool_s 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 ( 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   ) 
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.


Variable Documentation

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]

Definition at line 40 of file mem.c.

SDL_mutex* z_lock [static]

Definition at line 36 of file mem.c.

Referenced by _Mem_Alloc(), _Mem_Free(), Mem_Init(), and Mem_Shutdown().


Generated by  doxygen 1.6.2