UFO: Alien Invasion
Loading...
Searching...
No Matches
mem.h
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 1997-2001 Id Software, Inc.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#pragma once
27
28#include "../shared/cxx.h"
29struct 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 */
57memPool_t* _Mem_CreatePool(const char* name, const char* fileName, const int fileLine) __attribute__ ((malloc));
58void _Mem_DeletePool(memPool_t* pool, const char* fileName, const int fileLine);
59
60void _Mem_Free(void* ptr, const char* fileName, const int fileLine);
61void _Mem_FreeTag(memPool_t* pool, const int tagNum, const char* fileName, const int fileLine);
62void _Mem_FreePool(memPool_t* pool, const char* fileName, const int fileLine);
63void* _Mem_Alloc(size_t size, bool zeroFill, memPool_t* pool, const int tagNum, const char* fileName, const int fileLine) __attribute__ ((malloc));
64void* _Mem_ReAlloc(void* ptr, size_t size, const char* fileName, const int fileLine);
65
66char* _Mem_PoolStrDupTo(const char* in, char** out, memPool_t* pool, const int tagNum, const char* fileName, const int fileLine);
67void* _Mem_PoolDup(const void* in, size_t size, memPool_t* pool, const int tagNum, const char* fileName, const int fileLine);
68char* _Mem_PoolStrDup(const char* in, memPool_t* pool, const int tagNum, const char* fileName, const int fileLine) __attribute__ ((malloc));
69uint32_t _Mem_PoolSize(memPool_t* pool);
70uint32_t _Mem_ChangeTag(memPool_t* pool, const int tagFrom, const int tagTo);
71
72void _Mem_CheckGlobalIntegrity(const char* fileName, const int fileLine);
73
74bool _Mem_AllocatedInPool(memPool_t* pool, const void* pointer);
75
76void Mem_Init(void);
77void Mem_Shutdown(void);
78
79#ifdef COMPILE_UFO
80void Mem_InitCallbacks(void);
81void Mem_ShutdownCallbacks(void);
82#endif
#define __attribute__(x)
Definition cxx.h:37
voidpf void uLong size
Definition ioapi.h:42
memPool_t * _Mem_CreatePool(const char *name, const char *fileName, const int fileLine) __attribute__((malloc))
Definition mem.cpp:103
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
void Mem_Init(void)
Definition mem.cpp:506
void * _Mem_ReAlloc(void *ptr, size_t size, const char *fileName, const int fileLine)
Definition mem.cpp:333
void Mem_Shutdown(void)
Definition mem.cpp:518
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
void _Mem_DeletePool(memPool_t *pool, const char *fileName, const int fileLine)
Definition mem.cpp:146
void _Mem_FreePool(memPool_t *pool, const char *fileName, const int fileLine)
Free all items within a pool.
Definition mem.cpp:262
void _Mem_CheckGlobalIntegrity(const char *fileName, const int fileLine)
Definition mem.cpp:470
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.
uint32_t _Mem_ChangeTag(memPool_t *pool, const int tagFrom, const int tagTo)
Definition mem.cpp:426
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:407
uint32_t _Mem_PoolSize(memPool_t *pool)
Definition mem.cpp:418
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:486
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
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
QGL_EXTERN GLint GLenum GLboolean GLsizei const GLvoid * pointer
Definition r_gl.h:94