Home | History | Annotate | Download | only in jni
      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 /*
     21  memory allocation
     22 
     23 
     24 H_??? The hunk manages the entire memory block given to quake.  It must be
     25 contiguous.  Memory can be allocated from either the low or high end in a
     26 stack fashion.  The only way memory is released is by resetting one of the
     27 pointers.
     28 
     29 Hunk allocations should be given a name, so the Hunk_Print () function
     30 can display usage.
     31 
     32 Hunk allocations are guaranteed to be 16 byte aligned.
     33 
     34 The video buffers are allocated high to avoid leaving a hole underneath
     35 server allocations when changing to a higher video mode.
     36 
     37 
     38 Z_??? Zone memory functions used for small, dynamic allocations like text
     39 strings from command input.  There is only about 48K for it, allocated at
     40 the very bottom of the hunk.
     41 
     42 Cache_??? Cache memory is for objects that can be dynamically loaded and
     43 can usefully stay persistant between levels.  The size of the cache
     44 fluctuates from level to level.
     45 
     46 To allocate a cachable object
     47 
     48 
     49 Temp_??? Temp memory is used for file loading and surface caching.  The size
     50 of the cache memory is adjusted so that there is a minimum of 512k remaining
     51 for temp memory.
     52 
     53 
     54 ------ Top of Memory -------
     55 
     56 high hunk allocations
     57 
     58 <--- high hunk reset point held by vid
     59 
     60 video buffer
     61 
     62 z buffer
     63 
     64 surface cache
     65 
     66 <--- high hunk used
     67 
     68 cachable memory
     69 
     70 <--- low hunk used
     71 
     72 client and server low hunk allocations
     73 
     74 <-- low hunk reset point held by host
     75 
     76 startup hunk allocations
     77 
     78 Zone block
     79 
     80 ----- Bottom of Memory -----
     81 
     82 
     83 
     84 */
     85 
     86 void Memory_Init (void *buf, int size);
     87 
     88 void Z_Free (void *ptr);
     89 void *Z_Malloc (int size);			// returns 0 filled memory
     90 void *Z_TagMalloc (int size, int tag);
     91 
     92 void Z_DumpHeap (void);
     93 void Z_CheckHeap (void);
     94 int Z_FreeMemory (void);
     95 
     96 void *Hunk_Alloc (int size);		// returns 0 filled memory
     97 void *Hunk_AllocName (int size, const char *name);
     98 
     99 void *Hunk_HighAllocName (int size, const char *name);
    100 
    101 int	Hunk_LowMark (void);
    102 void Hunk_FreeToLowMark (int mark);
    103 
    104 int	Hunk_HighMark (void);
    105 void Hunk_FreeToHighMark (int mark);
    106 
    107 void *Hunk_TempAlloc (int size);
    108 
    109 void Hunk_Check (void);
    110 
    111 typedef struct cache_user_s
    112 {
    113 	void	*data;
    114 } cache_user_t;
    115 
    116 void Cache_Flush (void);
    117 
    118 void *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 
    122 void Cache_Free (cache_user_t *c);
    123 
    124 void *Cache_Alloc (cache_user_t *c, int size, const char *name);
    125 // Returns NULL if all purgable data was tossed and there still
    126 // wasn't enough room.
    127 
    128 void Cache_Report (void);
    129 
    130 
    131 
    132