1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 #ifndef __ZONE_H__
21 #define __ZONE_H__
22 
23 /*
24  memory allocation
25 
26 
27 H_??? The hunk manages the entire memory block given to quake.  It must be
28 contiguous.  Memory can be allocated from either the low or high end in a
29 stack fashion.  The only way memory is released is by resetting one of the
30 pointers.
31 
32 Hunk allocations should be given a name, so the Hunk_Print () function
33 can display usage.
34 
35 Hunk allocations are guaranteed to be 16 byte aligned.
36 
37 The video buffers are allocated high to avoid leaving a hole underneath
38 server allocations when changing to a higher video mode.
39 
40 
41 Cache_??? Cache memory is for objects that can be dynamically loaded and
42 can usefully stay persistent between levels.  The size of the cache
43 fluctuates from level to level.
44 
45 To allocate a cachable object
46 
47 
48 Temp_??? Temp memory is used for file loading and surface caching.  The size
49 of the cache memory is adjusted so that there is a minimum of 512k remaining
50 for temp memory.
51 
52 
53 ------ Top of Memory -------
54 
55 high hunk allocations
56 
57 <--- high hunk reset point held by vid
58 
59 video buffer
60 
61 z buffer
62 
63 surface cache
64 
65 <--- high hunk used
66 
67 cachable memory
68 
69 <--- low hunk used
70 
71 client and server low hunk allocations
72 
73 <-- low hunk reset point held by host
74 
75 startup hunk allocations
76 
77 ----- Bottom of Memory -----
78 
79 
80 
81 */
82 
83 void Memory_Init (void *buf, int size);
84 
85 void *Hunk_Alloc (int size); // returns 0 filled memory
86 void *Hunk_AllocName (int size, const char *name);
87 
88 void *Hunk_HighAllocName (int size, char *name);
89 
90 int	Hunk_LowMark (void);
91 void Hunk_FreeToLowMark (int mark);
92 
93 int	Hunk_HighMark (void);
94 void Hunk_FreeToHighMark (int mark);
95 
96 void *Hunk_TempAlloc (int size);
97 
98 void Hunk_Check (void);
99 
100 #ifdef SERVERONLY
101 typedef struct cache_user_s
102 {
103 	void *data;
104 } cache_user_t;
105 
106 void Cache_Flush (void);
107 
108 void *Cache_Check (cache_user_t *c);
109 // returns the cached data, and moves to the head of the LRU list
110 // if present, otherwise returns NULL
111 
112 void Cache_Free(cache_user_t *c);
113 
114 void *Cache_Alloc (cache_user_t *c, int size, const char *name);
115 // Returns NULL if all purgeable data was tossed and there still
116 // wasn't enough room.
117 
118 void Cache_Report (void);
119 void Cache_Init_Commands (void);
120 #endif
121 
122 #endif /* !__ZONE_H__ */
123