z_zone.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Emacs style mode select -*- C++ -*-
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // DESCRIPTION:
  18. // Zone Memory Allocation, perhaps NeXT ObjectiveC inspired.
  19. // Remark: this was the only stuff that, according
  20. // to John Carmack, might have been useful for
  21. // Quake.
  22. //
  23. //---------------------------------------------------------------------
  24. #ifndef __Z_ZONE__
  25. #define __Z_ZONE__
  26. #include <stdio.h>
  27. //
  28. // ZONE MEMORY
  29. // PU - purge tags.
  30. // Tags < 100 are not overwritten until freed.
  31. #define PU_STATIC 1 // static entire execution time
  32. #define PU_SOUND 2 // static while playing
  33. #define PU_MUSIC 3 // static while playing
  34. #define PU_DAVE 4 // anything else Dave wants static
  35. #define PU_LEVEL 50 // static until level exited
  36. #define PU_LEVSPEC 51 // a special thinker in a level
  37. // Tags >= 100 are purgable whenever needed.
  38. #define PU_PURGELEVEL 100
  39. #define PU_CACHE 101
  40. void Z_Init (void);
  41. void* Z_Malloc (int size, int tag, void *ptr);
  42. void Z_Free (void *ptr);
  43. void Z_FreeTags (int lowtag, int hightag);
  44. void Z_DumpHeap (int lowtag, int hightag);
  45. void Z_FileDumpHeap (FILE *f);
  46. void Z_CheckHeap (void);
  47. void Z_ChangeTag2 (void *ptr, int tag);
  48. int Z_FreeMemory (void);
  49. typedef struct memblock_s
  50. {
  51. int size; // including the header and possibly tiny fragments
  52. void** user; // NULL if a free block
  53. int tag; // purgelevel
  54. int id; // should be ZONEID
  55. struct memblock_s* next;
  56. struct memblock_s* prev;
  57. } memblock_t;
  58. //
  59. // This is used to get the local FILE:LINE info from CPP
  60. // prior to really call the function in question.
  61. //
  62. #define Z_ChangeTag(p,t) \
  63. { \
  64. if (( (memblock_t *)( (byte *)(p) - sizeof(memblock_t)))->id!=0x1d4a11) \
  65. I_Error("Z_CT at "__FILE__":%i",__LINE__); \
  66. Z_ChangeTag2(p,t); \
  67. };
  68. #endif
  69. //-----------------------------------------------------------------------------
  70. //
  71. // $Log:$
  72. //
  73. //-----------------------------------------------------------------------------