zone.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. /*
  16. memory allocation
  17. H_??? The hunk manages the entire memory block given to quake. It must be
  18. contiguous. Memory can be allocated from either the low or high end in a
  19. stack fashion. The only way memory is released is by resetting one of the
  20. pointers.
  21. Hunk allocations should be given a name, so the Hunk_Print () function
  22. can display usage.
  23. Hunk allocations are guaranteed to be 16 byte aligned.
  24. The video buffers are allocated high to avoid leaving a hole underneath
  25. server allocations when changing to a higher video mode.
  26. Z_??? Zone memory functions used for small, dynamic allocations like text
  27. strings from command input. There is only about 48K for it, allocated at
  28. the very bottom of the hunk.
  29. Cache_??? Cache memory is for objects that can be dynamically loaded and
  30. can usefully stay persistant between levels. The size of the cache
  31. fluctuates from level to level.
  32. To allocate a cachable object
  33. Temp_??? Temp memory is used for file loading and surface caching. The size
  34. of the cache memory is adjusted so that there is a minimum of 512k remaining
  35. for temp memory.
  36. ------ Top of Memory -------
  37. high hunk allocations
  38. <--- high hunk reset point held by vid
  39. video buffer
  40. z buffer
  41. surface cache
  42. <--- high hunk used
  43. cachable memory
  44. <--- low hunk used
  45. client and server low hunk allocations
  46. <-- low hunk reset point held by host
  47. startup hunk allocations
  48. Zone block
  49. ----- Bottom of Memory -----
  50. */
  51. void Memory_Init (void *buf, int size);
  52. void Z_Free (void *ptr);
  53. void *Z_Malloc (int size); // returns 0 filled memory
  54. void *Z_TagMalloc (int size, int tag);
  55. void Z_DumpHeap (void);
  56. void Z_CheckHeap (void);
  57. int Z_FreeMemory (void);
  58. void *Hunk_Alloc (int size); // returns 0 filled memory
  59. void *Hunk_AllocName (int size, char *name);
  60. void *Hunk_HighAllocName (int size, char *name);
  61. int Hunk_LowMark (void);
  62. void Hunk_FreeToLowMark (int mark);
  63. int Hunk_HighMark (void);
  64. void Hunk_FreeToHighMark (int mark);
  65. void *Hunk_TempAlloc (int size);
  66. void Hunk_Check (void);
  67. typedef struct cache_user_s
  68. {
  69. void *data;
  70. } cache_user_t;
  71. void Cache_Flush (void);
  72. void *Cache_Check (cache_user_t *c);
  73. // returns the cached data, and moves to the head of the LRU list
  74. // if present, otherwise returns NULL
  75. void Cache_Free (cache_user_t *c);
  76. void *Cache_Alloc (cache_user_t *c, int size, char *name);
  77. // Returns NULL if all purgable data was tossed and there still
  78. // wasn't enough room.
  79. void Cache_Report (void);