FTEQW
Documentation of the FTE engine source tree.
zone.h
Go to the documentation of this file.
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20/*
21 memory allocation
22
23
24H_??? The hunk manages the entire memory block given to quake. It must be
25contiguous. Memory can be allocated from either the low or high end in a
26stack fashion. The only way memory is released is by resetting one of the
27pointers.
28
29Hunk allocations should be given a name, so the Hunk_Print () function
30can display usage.
31
32Hunk allocations are guaranteed to be 16 byte aligned.
33
34The video buffers are allocated high to avoid leaving a hole underneath
35server allocations when changing to a higher video mode.
36
37
38Z_??? Zone memory functions used for small, dynamic allocations like text
39strings from command input. There is only about 48K for it, allocated at
40the very bottom of the hunk.
41
42Cache_??? Cache memory is for objects that can be dynamically loaded and
43can usefully stay persistant between levels. The size of the cache
44fluctuates from level to level.
45
46To allocate a cachable object
47
48
49Temp_??? Temp memory is used for file loading and surface caching. The size
50of the cache memory is adjusted so that there is a minimum of 512k remaining
51for temp memory.
52
53
54------ Top of Memory -------
55
56high hunk allocations
57
58<--- high hunk reset point held by vid
59
60video buffer
61
62z buffer
63
64surface cache
65
66<--- high hunk used
67
68cachable memory
69
70<--- low hunk used
71
72client and server low hunk allocations
73
74<-- low hunk reset point held by host
75
76startup hunk allocations
77
78Zone block
79
80----- Bottom of Memory -----
81
82
83
84*/
85
86#if 0//defined(_DEBUG) && defined(__linux__) && !defined(ANDROID)
87 #include <valgrind/memcheck.h>
88#else
89 #define VALGRIND_MAKE_MEM_UNDEFINED(ptr,sz) //as an alternative to memzero..
90 #define VALGRIND_MAKE_MEM_NOACCESS(ptr,sz)
91 #define VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(ptr,sz) //undo VALGRIND_MAKE_MEM_UNDEFINED, to make sure we don't read past the end of buffers.
92#endif
93
94void Memory_Init (void);
95void Memory_DeInit(void);
96
97//Prefixes:
98//Z - just general 'zone' memory.
99//B - allocated memory is not zero-filled.
100//F - allocation can return NULL (otherwise sys_errors)
101//G - special set of functions with its own rules. Frees must not be mixed.
102//Tag - additional special set of functions with their own rules. Frees must not be mixed.
103void VARGS Z_Free (void *ptr);
104void *Z_Malloc (size_t size); // returns 0 filled memory
105void *ZF_Malloc (size_t size); // allowed to fail
106void *Z_MallocNamed (size_t size, char *file, int line); // returns 0 filled memory
107void *ZF_MallocNamed (size_t size, char *file, int line); // allowed to fail
108//#define Z_Malloc(x) Z_MallocNamed2(x, __FILE__, __LINE__ )
109void *Z_TagMalloc (size_t size, int tag);
110void VARGS Z_TagFree(void *ptr);
111void VARGS Z_FreeTags(int tag);
112qboolean ZF_ReallocElements(void **ptr, size_t *elements, size_t newelements, size_t elementsize); //returns false on error
113qboolean ZF_ReallocElementsNamed(void **ptr, size_t *elements, size_t newelements, size_t elementsize, const char *file, int line); //returns false on error
114#define Z_ReallocElements(ptr,elements,newelements,elementsize) do{if (!ZF_ReallocElements(ptr,elements,newelements,elementsize))Sys_Error("Z_ReallocElements failed (%s %i)\n", __FILE__, __LINE__);}while(0) //returns false on error
115
116//Big Zone: allowed to fail, doesn't clear. The expectation is a large file, rather than sensitive data structures.
117//(this is a nicer name for malloc)
118void *BZ_Malloc(size_t size);
119void *BZF_Malloc(size_t size);
120void *BZ_MallocNamed (size_t size, const char *file, int line); // returns 0 filled memory
121void *BZF_MallocNamed (size_t size, const char *file, int line); // allowed to fail
122void *BZ_Realloc(void *ptr, size_t size);
123void *BZ_ReallocNamed(void *data, size_t newsize, const char *file, int line);
124void *BZF_Realloc(void *data, size_t newsize);
125void *BZF_ReallocNamed(void *data, size_t newsize, const char *file, int line);
126void BZ_Free(void *ptr);
127
128//ctx should start off as void*ctx=NULL
129typedef struct zonegroup_s
130{
131 void *first;
132 int totalbytes; //combined size of all mallocs in this group
134void *QDECL ZG_Malloc(zonegroup_t *ctx, size_t size);
135void *ZG_MallocNamed(zonegroup_t *ctx, size_t size, char *file, int line);
136void QDECL ZG_Free(zonegroup_t *ctx, void *ptr);
137void QDECL ZG_FreeGroup(zonegroup_t *ctx);
138
139#ifdef USE_MSVCRT_DEBUG
140#define BZ_Malloc(size) BZ_MallocNamed(size, __FILE__, __LINE__)
141#define Z_Malloc(size) Z_MallocNamed(size, __FILE__, __LINE__)
142#define BZ_Realloc(ptr, size) BZ_ReallocNamed(ptr, size, __FILE__, __LINE__)
143#define BZF_Malloc(size) BZF_MallocNamed(size, __FILE__, __LINE__)
144#define ZF_Malloc(size) ZF_MallocNamed(size, __FILE__, __LINE__)
145#define BZF_Realloc(ptr, size) BZF_ReallocNamed(ptr, size, __FILE__, __LINE__)
146#define ZG_Malloc(ctx, size) ZG_MallocNamed(ctx, size, __FILE__, __LINE__)
147#define ZF_ReallocElements(p,e,n,s) ZF_ReallocElementsNamed(p,e,n,s,__FILE__,__LINE__)
148#endif
149#define Z_StrDup(s) strcpy(Z_Malloc(strlen(s)+1), s)
150#define Z_StrDupPtr(v,s) do{Z_Free(*v),*(v) = strcpy(Z_Malloc(strlen(s)+1), s);}while(0)
151
152char *Z_StrDupf(const char *format, ...);
153void Z_StrCat(char **ptr, const char *append);
154void Z_StrCatLen(char **ptr, const char *append, size_t newlen); //still doesn't allow nulls, but src doesn't need null termination.
155
156/*
157void *Hunk_Alloc (int size); // returns 0 filled memory
158void *Hunk_AllocName (int size, char *name);
159*/
160
161void *Hunk_TempAlloc (size_t size);
162void *Hunk_TempAllocMore (size_t size); //Don't clear old temp
163
164/*
165typedef struct cache_user_s
166{
167 void *data;
168 qboolean fake;
169} cache_user_t;
170*/
171void Cache_Flush (void);
172/*
173void *Cache_Check (cache_user_t *c);
174// returns the cached data, and moves to the head of the LRU list
175// if present, otherwise returns NULL
176
177void Cache_Free (cache_user_t *c);
178
179void *Cache_Alloc (cache_user_t *c, int size, char *name);
180// Returns NULL if all purgable data was tossed and there still
181// wasn't enough room.
182
183void Cache_Report (void);
184*/
qboolean
Definition: api_menu.h:34
static EGLSurface EGLSurface EGLContext ctx
Definition: gl_videgl.c:47
GLint size
Definition: glquake.h:157
GLenum format
Definition: glsupp.h:502
char ** data
Definition: p_script.c:63
const char * file
Definition: qcc_pr_lex.c:2518
static int void * ptr
Definition: snd_dma.c:483
Definition: zone.h:130
int totalbytes
Definition: zone.h:132
void * first
Definition: zone.h:131
qboolean size_t * elements
Definition: zone.c:397
qboolean size_t size_t size_t elementsize
Definition: zone.c:399
qboolean size_t size_t newelements
Definition: zone.c:397
size_t newsize
Definition: zone.c:402
void * Hunk_TempAllocMore(size_t size)
Definition: zone.c:680
void Z_StrCat(char **ptr, const char *append)
Definition: zone.c:267
char * Z_StrDupf(const char *format,...)
Definition: zone.c:219
void * BZ_Realloc(void *ptr, size_t size)
Definition: zone.c:532
void QDECL ZG_FreeGroup(zonegroup_t *ctx)
Definition: zone.c:613
void VARGS Z_FreeTags(int tag)
Definition: zone.c:341
void * BZF_ReallocNamed(void *data, size_t newsize, const char *file, int line)
void VARGS Z_Free(void *ptr)
Definition: zone.c:336
void VARGS Z_TagFree(void *ptr)
Definition: zone.c:279
struct zonegroup_s zonegroup_t
void Z_StrCatLen(char **ptr, const char *append, size_t newlen)
Definition: zone.c:257
void * BZ_ReallocNamed(void *data, size_t newsize, const char *file, int line)
void * Z_TagMalloc(size_t size, int tag)
Definition: zone.c:114
void * ZF_MallocNamed(size_t size, char *file, int line)
void * BZ_MallocNamed(size_t size, const char *file, int line)
void *QDECL ZG_Malloc(zonegroup_t *ctx, size_t size)
void Cache_Flush(void)
Definition: zone.c:728
void Memory_DeInit(void)
Definition: zone.c:834
qboolean ZF_ReallocElementsNamed(void **ptr, size_t *elements, size_t newelements, size_t elementsize, const char *file, int line)
void * BZF_Malloc(size_t size)
Definition: zone.c:478
void * BZF_MallocNamed(size_t size, const char *file, int line)
void QDECL ZG_Free(zonegroup_t *ctx, void *ptr)
void * Z_Malloc(size_t size)
Definition: zone.c:209
void Memory_Init(void)
Definition: zone.c:801
void * ZF_Malloc(size_t size)
Definition: zone.c:190
void * Z_MallocNamed(size_t size, char *file, int line)
void * BZF_Realloc(void *data, size_t newsize)
Definition: zone.c:527
void * BZ_Malloc(size_t size)
Definition: zone.c:501
void * Hunk_TempAlloc(size_t size)
Definition: zone.c:714
void * ZG_MallocNamed(zonegroup_t *ctx, size_t size, char *file, int line)
qboolean ZF_ReallocElements(void **ptr, size_t *elements, size_t newelements, size_t elementsize)
void BZ_Free(void *ptr)
Definition: sys_plugfte.c:77