UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mem.h
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 1997-2001 Id Software, Inc.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24 */
25 
26 #pragma once
27 
28 #include "../shared/cxx.h"
29 struct memPool_t;
30 
31 /* constants */
32 #define Mem_CreatePool(name) _Mem_CreatePool((name),__FILE__,__LINE__)
33 #define Mem_DeletePool(pool) _Mem_DeletePool((pool),__FILE__,__LINE__)
34 
35 #define Mem_Free(ptr) _Mem_Free((ptr),__FILE__,__LINE__)
36 #define Mem_FreeTag(pool,tagNum) _Mem_FreeTag((pool),(tagNum),__FILE__,__LINE__)
37 #define Mem_FreePool(pool) _Mem_FreePool((pool),__FILE__,__LINE__)
38 #define Mem_AllocTypeN(type, n) static_cast<type*>(Mem_Alloc(sizeof(type) * (n)))
39 #define Mem_AllocType(type) static_cast<type*>(Mem_Alloc(sizeof(type)))
40 #define Mem_Alloc(size) Mem_PoolAlloc((size), com_genericPool, 0)
41 #define Mem_PoolAlloc(size,pool,tagNum) _Mem_Alloc((size),true,(pool),(tagNum),__FILE__,__LINE__)
42 #define Mem_PoolAllocTypeN(type, n, pool) static_cast<type*>(Mem_PoolAlloc(sizeof(type) * (n), (pool), 0))
43 #define Mem_PoolAllocType(type, pool) static_cast<type*>(Mem_PoolAllocTypeN(type, 1, (pool)))
44 #define Mem_ReAlloc(ptr,size) _Mem_ReAlloc((ptr),(size),__FILE__,__LINE__)
45 #define Mem_SafeReAlloc(ptr, size) ((ptr) ? Mem_ReAlloc(ptr, size) : Mem_Alloc(size))
46 
47 #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__))
48 #define Mem_StrDup(in) _Mem_PoolStrDup((in),com_genericPool,0,__FILE__,__LINE__)
49 #define Mem_PoolStrDupTo(in,out,pool,tagNum) _Mem_PoolStrDupTo((in),(out),(pool),(tagNum),__FILE__,__LINE__)
50 #define Mem_PoolStrDup(in,pool,tagNum) _Mem_PoolStrDup((in),(pool),(tagNum),__FILE__,__LINE__)
51 #define Mem_PoolSize(pool) _Mem_PoolSize((pool))
52 #define Mem_ChangeTag(pool,tagFrom,tagTo) _Mem_ChangeTag((pool),(tagFrom),(tagTo))
53 
54 #define Mem_CheckGlobalIntegrity() _Mem_CheckGlobalIntegrity(__FILE__,__LINE__)
55 
56 /* functions */
57 memPool_t* _Mem_CreatePool(const char* name, const char* fileName, const int fileLine) __attribute__ ((malloc));
58 void _Mem_DeletePool(memPool_t* pool, const char* fileName, const int fileLine);
59 
60 void _Mem_Free(void* ptr, const char* fileName, const int fileLine);
61 void _Mem_FreeTag(memPool_t* pool, const int tagNum, const char* fileName, const int fileLine);
62 void _Mem_FreePool(memPool_t* pool, const char* fileName, const int fileLine);
63 void* _Mem_Alloc(size_t size, bool zeroFill, memPool_t* pool, const int tagNum, const char* fileName, const int fileLine) __attribute__ ((malloc));
64 void* _Mem_ReAlloc(void* ptr, size_t size, const char* fileName, const int fileLine);
65 
66 char* _Mem_PoolStrDupTo(const char* in, char** out, memPool_t* pool, const int tagNum, const char* fileName, const int fileLine);
67 void* _Mem_PoolDup(const void* in, size_t size, memPool_t* pool, const int tagNum, const char* fileName, const int fileLine);
68 char* _Mem_PoolStrDup(const char* in, memPool_t* pool, const int tagNum, const char* fileName, const int fileLine) __attribute__ ((malloc));
69 uint32_t _Mem_PoolSize(memPool_t* pool);
70 uint32_t _Mem_ChangeTag(memPool_t* pool, const int tagFrom, const int tagTo);
71 
72 void _Mem_CheckGlobalIntegrity(const char* fileName, const int fileLine);
73 
74 bool _Mem_AllocatedInPool(memPool_t* pool, const void* pointer);
75 
76 void Mem_Init(void);
77 void Mem_Shutdown(void);
void _Mem_FreePool(memPool_t *pool, const char *fileName, const int fileLine)
Free all items within a pool.
Definition: mem.cpp:260
QGL_EXTERN GLint GLenum GLboolean GLsizei const GLvoid * pointer
Definition: r_gl.h:94
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.
Definition: mem.cpp:403
uint32_t _Mem_PoolSize(memPool_t *pool)
Definition: mem.cpp:414
void Mem_Shutdown(void)
Definition: mem.cpp:603
#define __attribute__(x)
Definition: cxx.h:37
void Mem_Init(void)
Definition: mem.cpp:588
GLsizei size
Definition: r_gl.h:152
void _Mem_Free(void *ptr, const char *fileName, const int fileLine)
Definition: mem.cpp:204
bool _Mem_AllocatedInPool(memPool_t *pool, const void *pointer)
Definition: mem.cpp:482
void * _Mem_PoolDup(const void *in, size_t size, memPool_t *pool, const int tagNum, const char *fileName, const int fileLine)
Definition: mem.cpp:385
memPool_t * _Mem_CreatePool(const char *name, const char *fileName, const int fileLine) __attribute__((malloc))
Definition: mem.cpp:103
void _Mem_CheckGlobalIntegrity(const char *fileName, const int fileLine)
Definition: mem.cpp:466
void _Mem_DeletePool(memPool_t *pool, const char *fileName, const int fileLine)
Definition: mem.cpp:146
void * _Mem_ReAlloc(void *ptr, size_t size, const char *fileName, const int fileLine)
Definition: mem.cpp:329
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
uint32_t _Mem_ChangeTag(memPool_t *pool, const int tagFrom, const int tagTo)
Definition: mem.cpp:422
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.
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:377
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:241