2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
zone.h
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
2001-02-21 19:35:06 +00:00
|
|
|
#ifndef __zone_h
|
|
|
|
#define __zone_h
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \defgroup zone Memory Management
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup utils
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
H_??? The hunk manages the entire memory block given to quake. It must be
|
|
|
|
contiguous. Memory can be allocated from either the low or high end in a
|
|
|
|
stack fashion. The only way memory is released is by resetting one of the
|
|
|
|
pointers.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
Hunk allocations should be given a name, so the Hunk_Print () function
|
|
|
|
can display usage.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
Hunk allocations are guaranteed to be 16 byte aligned.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
The video buffers are allocated high to avoid leaving a hole underneath
|
|
|
|
server allocations when changing to a higher video mode.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
Z_??? Zone memory functions used for small, dynamic allocations like text
|
|
|
|
strings from command input. There is only about 48K for it, allocated at
|
|
|
|
the very bottom of the hunk.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
Cache_??? Cache memory is for objects that can be dynamically loaded and
|
|
|
|
can usefully stay persistant between levels. The size of the cache
|
|
|
|
fluctuates from level to level.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
To allocate a cachable object
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
Temp_??? Temp memory is used for file loading and surface caching. The
|
|
|
|
size of the cache memory is adjusted so that there is a minimum of 512k
|
|
|
|
remaining for temp memory.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
------ Top of Memory -------
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
high hunk allocations
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
<--- high hunk reset point held by vid
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
video buffer
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
z buffer
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
surface cache
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
<--- high hunk used
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
cachable memory
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
<--- low hunk used
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
client and server low hunk allocations
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
<-- low hunk reset point held by host
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
startup hunk allocations
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
Zone block
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
----- Bottom of Memory -----
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2004-11-08 23:27:00 +00:00
|
|
|
//@{
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 05:21:30 +00:00
|
|
|
typedef struct memzone_s memzone_t;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 05:21:30 +00:00
|
|
|
void Memory_Init (void *buf, int size);
|
2001-08-28 04:24:40 +00:00
|
|
|
|
2011-03-08 13:44:56 +00:00
|
|
|
void Z_ClearZone (memzone_t *zone, int size, int zone_offset, int ele_size);
|
2001-08-28 05:21:30 +00:00
|
|
|
void Z_Free (memzone_t *zone, void *ptr);
|
|
|
|
void *Z_Malloc (memzone_t *zone, int size); // returns 0 filled memory
|
|
|
|
void *Z_TagMalloc (memzone_t *zone, int size, int tag);
|
2002-05-29 20:58:53 +00:00
|
|
|
void *Z_Realloc (memzone_t *zone, void *ptr, int size);
|
2004-11-14 00:49:00 +00:00
|
|
|
void Z_Print (memzone_t *zone);
|
2001-08-28 05:21:30 +00:00
|
|
|
void Z_CheckHeap (memzone_t *zone);
|
2012-02-06 03:48:22 +00:00
|
|
|
void Z_SetError (memzone_t *zone, void (*err) (void *data, const char *msg),
|
|
|
|
void *data);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2007-03-28 09:52:01 +00:00
|
|
|
void *Hunk_Alloc (int size); // returns 0 filled memory
|
|
|
|
void *Hunk_AllocName (int size, const char *name);
|
2001-02-19 21:15:25 +00:00
|
|
|
int Hunk_LowMark (void);
|
|
|
|
void Hunk_FreeToLowMark (int mark);
|
|
|
|
void *Hunk_TempAlloc (int size);
|
|
|
|
void Hunk_Check (void);
|
|
|
|
|
2007-03-28 09:52:01 +00:00
|
|
|
|
|
|
|
|
2001-08-30 11:37:50 +00:00
|
|
|
struct cache_user_s;
|
2007-03-28 09:52:01 +00:00
|
|
|
typedef void *(*cache_allocator_t) (struct cache_user_s *c, int size, const char *name);
|
2001-08-31 12:22:45 +00:00
|
|
|
typedef void (*cache_loader_t) (void *object, cache_allocator_t allocator);
|
2007-03-28 09:52:01 +00:00
|
|
|
typedef struct cache_user_s {
|
2001-02-19 21:15:25 +00:00
|
|
|
void *data;
|
2001-08-31 12:22:45 +00:00
|
|
|
void *object;
|
2001-08-30 11:37:50 +00:00
|
|
|
cache_loader_t loader;
|
2001-02-19 21:15:25 +00:00
|
|
|
} cache_user_t;
|
|
|
|
|
|
|
|
void Cache_Flush (void);
|
|
|
|
void *Cache_Check (cache_user_t *c);
|
|
|
|
// returns the cached data, and moves to the head of the LRU list
|
|
|
|
// if present, otherwise returns NULL
|
|
|
|
|
|
|
|
void Cache_Free (cache_user_t *c);
|
2001-07-15 07:04:17 +00:00
|
|
|
void *Cache_Alloc (cache_user_t *c, int size, const char *name);
|
2001-02-19 21:15:25 +00:00
|
|
|
// Returns NULL if all purgable data was tossed and there still
|
|
|
|
// wasn't enough room.
|
|
|
|
void Cache_Report (void);
|
2001-08-31 12:22:45 +00:00
|
|
|
void Cache_Add (cache_user_t *c, void *object, cache_loader_t loader);
|
2001-08-30 11:37:50 +00:00
|
|
|
void Cache_Remove (cache_user_t *c);
|
2001-08-31 03:48:26 +00:00
|
|
|
void *Cache_TryGet (cache_user_t *c);
|
2007-03-28 13:09:49 +00:00
|
|
|
void *Cache_Get (cache_user_t *c);
|
2001-08-30 11:37:50 +00:00
|
|
|
void Cache_Release (cache_user_t *c);
|
2007-03-23 12:36:55 +00:00
|
|
|
int Cache_ReadLock (cache_user_t *c);
|
2001-08-30 11:37:50 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
//@}
|
|
|
|
|
2001-02-21 19:35:06 +00:00
|
|
|
#endif // __zone_h
|