|
Odamex
Setting the Standard in Multiplayer Doom
|
00001 // Emacs style mode select -*- C++ -*- 00002 //----------------------------------------------------------------------------- 00003 // 00004 // $Id: z_zone.h 1873 2010-09-07 01:06:06Z mike $ 00005 // 00006 // Copyright (C) 1993-1996 by id Software, Inc. 00007 // Copyright (C) 2006-2010 by The Odamex Team. 00008 // 00009 // This source is available for distribution and/or modification 00010 // only under the terms of the DOOM Source Code License as 00011 // published by id Software. All rights reserved. 00012 // 00013 // The source is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License 00016 // for more details. 00017 // 00018 // DESCRIPTION: 00019 // Zone Memory Allocation, perhaps NeXT ObjectiveC inspired. 00020 // Remark: this was the only stuff that, according 00021 // to John Carmack, might have been useful for 00022 // Quake. 00023 // 00024 //--------------------------------------------------------------------- 00025 00026 00027 #ifndef __Z_ZONE_H__ 00028 #define __Z_ZONE_H__ 00029 00030 #include <stdio.h> 00031 00032 // 00033 // ZONE MEMORY 00034 // PU - purge tags. 00035 // Tags < 100 are not overwritten until freed. 00036 #define PU_STATIC 1 // static entire execution time 00037 #define PU_SOUND 2 // static while playing 00038 #define PU_MUSIC 3 // static while playing 00039 #define PU_DAVE 4 // anything else Dave wants static 00040 #define PU_FREE 5 // a free block [ML] 12/4/06: Readded from Chocodoom 00041 #define PU_LEVEL 50 // static until level exited 00042 #define PU_LEVSPEC 51 // a special thinker in a level 00043 #define PU_LEVACS 52 // [RH] An ACS script in a level 00044 // Tags >= 100 are purgable whenever needed. 00045 #define PU_PURGELEVEL 100 00046 #define PU_CACHE 101 00047 00048 00049 void Z_Init (void); 00050 void Z_FreeTags (int lowtag, int hightag); 00051 void Z_DumpHeap (int lowtag, int hightag); 00052 void Z_FileDumpHeap (FILE *f); 00053 void Z_CheckHeap (void); 00054 size_t Z_FreeMemory (void); 00055 00056 // Don't use these, use the macros instead! 00057 void* Z_Malloc2 (size_t size, int tag, void *user, const char *file, int line); 00058 void Z_Free2 (void *ptr, const char *file, int line); 00059 void Z_ChangeTag2 (void *ptr, int tag); 00060 00061 typedef struct memblock_s 00062 { 00063 size_t size; // including the header and possibly tiny fragments 00064 void** user; // NULL if a free block 00065 int tag; // PU_FREE if this is free [ML] 12/4/06: Readded from Chocodoom 00066 int id; // should be ZONEID 00067 struct memblock_s* next; 00068 struct memblock_s* prev; 00069 } memblock_t; 00070 00071 inline void Z_ChangeTag2 (const void *ptr, int tag) 00072 { 00073 Z_ChangeTag2 (const_cast<void *>(ptr), tag); 00074 } 00075 // 00076 // This is used to get the local FILE:LINE info from CPP 00077 // prior to really calling the function in question. 00078 // 00079 #define Z_ChangeTag(p,t) \ 00080 { \ 00081 if (( (memblock_t *)( (byte *)(p) - sizeof(memblock_t)))->id!=0x1d4a11) \ 00082 I_Error("Z_ChangeTag at "__FILE__":%i",__LINE__); \ 00083 Z_ChangeTag2(p,t); \ 00084 }; 00085 00086 #define Z_ChangeTagSafe(p,t) \ 00087 { \ 00088 if (( (memblock_t *)( (char *)(p) - sizeof(memblock_t)))->tag > t) \ 00089 Z_ChangeTag (p,t); \ 00090 } 00091 00092 #define Z_Malloc(s,t,p) Z_Malloc2(s,t,p,__FILE__,__LINE__) 00093 #define Z_Free(p) Z_Free2(p,__FILE__,__LINE__) 00094 00095 #endif // __Z_ZONE_H__