z_zone.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2000 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. * DESCRIPTION:
  30. * Zone Memory Allocation, perhaps NeXT ObjectiveC inspired.
  31. * Remark: this was the only stuff that, according
  32. * to John Carmack, might have been useful for
  33. * Quake.
  34. *
  35. * Rewritten by Lee Killough, though, since it was not efficient enough.
  36. *
  37. *---------------------------------------------------------------------*/
  38. #ifndef __Z_ZONE__
  39. #define __Z_ZONE__
  40. #ifndef __GNUC__
  41. #define __attribute__(x)
  42. #endif
  43. // Include system definitions so that prototypes become
  44. // active before macro replacements below are in effect.
  45. #ifdef HAVE_CONFIG_H
  46. #include "config.h"
  47. #endif
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <assert.h>
  52. // ZONE MEMORY
  53. // PU - purge tags.
  54. enum {PU_FREE, PU_STATIC, PU_SOUND, PU_MUSIC, PU_LEVEL, PU_LEVSPEC, PU_CACHE,
  55. /* Must always be last -- killough */ PU_MAX};
  56. #define PU_PURGELEVEL PU_CACHE /* First purgable tag's level */
  57. #ifdef INSTRUMENTED
  58. #define DA(x,y) ,x,y
  59. #define DAC(x,y) x,y
  60. #else
  61. #define DA(x,y)
  62. #define DAC(x,y)
  63. #endif
  64. void *(Z_Malloc)(size_t size, int tag, void **ptr DA(const char *, int));
  65. void (Z_Free)(void *ptr DA(const char *, int));
  66. void (Z_FreeTags)(int lowtag, int hightag DA(const char *, int));
  67. void (Z_ChangeTag)(void *ptr, int tag DA(const char *, int));
  68. void (Z_Init)(void);
  69. void Z_Close(void);
  70. void *(Z_Calloc)(size_t n, size_t n2, int tag, void **user DA(const char *, int));
  71. void *(Z_Realloc)(void *p, size_t n, int tag, void **user DA(const char *, int));
  72. char *(Z_Strdup)(const char *s, int tag, void **user DA(const char *, int));
  73. void (Z_CheckHeap)(DAC(const char *,int)); // killough 3/22/98: add file/line info
  74. void Z_DumpHistory(char *);
  75. #ifdef INSTRUMENTED
  76. /* cph - save space if not debugging, don't require file
  77. * and line to memory calls */
  78. #define Z_Free(a) (Z_Free) (a, __FILE__,__LINE__)
  79. #define Z_FreeTags(a,b) (Z_FreeTags) (a,b, __FILE__,__LINE__)
  80. #define Z_ChangeTag(a,b) (Z_ChangeTag)(a,b, __FILE__,__LINE__)
  81. #define Z_Malloc(a,b,c) (Z_Malloc) (a,b,c, __FILE__,__LINE__)
  82. #define Z_Strdup(a,b,c) (Z_Strdup) (a,b,c, __FILE__,__LINE__)
  83. #define Z_Calloc(a,b,c,d) (Z_Calloc) (a,b,c,d,__FILE__,__LINE__)
  84. #define Z_Realloc(a,b,c,d) (Z_Realloc) (a,b,c,d,__FILE__,__LINE__)
  85. #define Z_CheckHeap() (Z_CheckHeap)(__FILE__,__LINE__)
  86. #endif
  87. /* cphipps 2001/11/18 -
  88. * If we're using memory mapped file access to WADs, we won't need to maintain
  89. * our own heap. So we *could* let "normal" malloc users use the libc malloc
  90. * directly, for efficiency. Except we do need a wrapper to handle out of memory
  91. * errors... damn, ok, we'll leave it for now.
  92. */
  93. #ifndef HAVE_LIBDMALLOC
  94. // Remove all definitions before including system definitions
  95. #undef malloc
  96. #undef free
  97. #undef realloc
  98. #undef calloc
  99. #undef strdup
  100. #define malloc(n) Z_Malloc(n,PU_STATIC,0)
  101. #define free(p) Z_Free(p)
  102. #define realloc(p,n) Z_Realloc(p,n,PU_STATIC,0)
  103. #define calloc(n1,n2) Z_Calloc(n1,n2,PU_STATIC,0)
  104. #define strdup(s) Z_Strdup(s,PU_STATIC,0)
  105. #else
  106. #ifdef HAVE_LIBDMALLOC
  107. #include <dmalloc.h>
  108. #endif
  109. #endif
  110. void Z_ZoneHistory(char *);
  111. #endif