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
86void Memory_Init (void *buf, int size);
87
88void Z_Free (void *ptr);
89void *Z_Malloc (int size);			// returns 0 filled memory
90void *Z_TagMalloc (int size, int tag);
91
92void Z_DumpHeap (void);
93void Z_CheckHeap (void);
94int Z_FreeMemory (void);
95
96void *Hunk_Alloc (int size);		// returns 0 filled memory
97void *Hunk_AllocName (int size, char *name);
98
99void *Hunk_HighAllocName (int size, char *name);
100
101int	Hunk_LowMark (void);
102void Hunk_FreeToLowMark (int mark);
103
104int	Hunk_HighMark (void);
105void Hunk_FreeToHighMark (int mark);
106
107void *Hunk_TempAlloc (int size);
108
109void Hunk_Check (void);
110
111typedef struct cache_user_s
112{
113	void	*data;
114} cache_user_t;
115
116void Cache_Flush (void);
117
118void *Cache_Check (cache_user_t *c);
119// returns the cached data, and moves to the head of the LRU list
120// if present, otherwise returns NULL
121
122void Cache_Free (cache_user_t *c);
123
124void *Cache_Alloc (cache_user_t *c, int size, char *name);
125// Returns NULL if all purgable data was tossed and there still
126// wasn't enough room.
127
128void Cache_Report (void);
129
130
131
132