z_zone.h (3978B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. 23 24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. 25 26 =========================================================================== 27 */ 28 29 #ifndef __Z_ZONE__ 30 #define __Z_ZONE__ 31 32 #include <stdio.h> 33 34 // 35 // ZONE MEMORY 36 // PU - purge tags. 37 // Tags < 100 are not overwritten until freed. 38 #define PU_STATIC 1 // static entire execution time 39 #define PU_SOUND 2 // static while playing 40 #define PU_MUSIC 3 // static while playing 41 #define PU_LEVEL 50 // static until level exited 42 #define PU_LEVSPEC 51 // a special thinker in a level 43 // Tags >= 100 are purgable whenever needed. 44 #define PU_PURGELEVEL 100 45 #define PU_CACHE 101 46 47 /* 48 #define PU_STATIC_SHARED 4 // static entire execution time 49 #define PU_SOUND_SHARED 5 // static while playing 50 #define PU_MUSIC_SHARED 6 // static while playing 51 #define PU_LEVEL_SHARED 52 // static until level exited 52 #define PU_LEVSPEC_SHARED 53 // a special thinker in a level 53 #define PU_CACHE_SHARED 102 54 */ 55 #define PU_STATIC_SHARED PU_STATIC // static entire execution time 56 #define PU_SOUND_SHARED PU_SOUND // static while playing 57 #define PU_MUSIC_SHARED PU_MUSIC // static while playing 58 #define PU_LEVEL_SHARED PU_LEVEL // static until level exited 59 #define PU_LEVSPEC_SHARED PU_LEVSPEC // a special thinker in a level 60 #define PU_CACHE_SHARED PU_CACHE 61 62 63 bool Z_IsStatic( int tag ); 64 65 void Z_Init (void); 66 void* Z_Malloc (int size, int tag, void *ptr); 67 void Z_Free (void *ptr); 68 void Z_FreeTag(int lowtag ); 69 void Z_FreeTags(int lowtag, int hightag ); 70 void Z_DumpHeap (int lowtag, int hightag); 71 void Z_FileDumpHeap (FILE *f); 72 void Z_CheckHeap (void); 73 void Z_ChangeTag2 (void **ptr, int tag); 74 int Z_FreeMemory (void); 75 76 77 //bool MallocForLump( int lump, size_t size, void **ptr, int tag ); 78 79 80 template< class _type_ > 81 bool MallocForLump( int lump, size_t size, _type_ * & ptr, int tag ) { 82 ptr = static_cast< _type_ * >( Z_Malloc( size, tag, 0 ) ); 83 84 return true; 85 } 86 87 88 typedef struct memblock_s 89 { 90 int size; // including the header and possibly tiny fragments 91 void** user; // NULL if a free block 92 int tag; // purgelevel 93 int id; // should be ZONEID 94 struct memblock_s* next; 95 struct memblock_s* prev; 96 } memblock_t; 97 98 99 // 100 // This is used to get the local FILE:LINE info from CPP 101 // prior to really call the function in question. 102 // 103 #define Z_ChangeTag(p,t) \ 104 { \ 105 if (( (memblock_t *)( (byte *)(p) - sizeof(memblock_t)))->id!=0x1d4a11) \ 106 I_Error("Z_CT at "__FILE__":%i",__LINE__); \ 107 Z_ChangeTag2((void**)&p,t); \ 108 }; 109 110 111 112 #endif 113