|
|
1.1 ! root 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: ! 25: ! 26: ! 27: #ifndef __Z_ZONE__ ! 28: #define __Z_ZONE__ ! 29: ! 30: #include <stdio.h> ! 31: ! 32: // ! 33: // ZONE MEMORY ! 34: // PU - purge tags. ! 35: // Tags < 100 are not overwritten until freed. ! 36: #define PU_STATIC 1 // static entire execution time ! 37: #define PU_SOUND 2 // static while playing ! 38: #define PU_MUSIC 3 // static while playing ! 39: #define PU_DAVE 4 // anything else Dave wants static ! 40: #define PU_LEVEL 50 // static until level exited ! 41: #define PU_LEVSPEC 51 // a special thinker in a level ! 42: // Tags >= 100 are purgable whenever needed. ! 43: #define PU_PURGELEVEL 100 ! 44: #define PU_CACHE 101 ! 45: ! 46: ! 47: void Z_Init (void); ! 48: void* Z_Malloc (int size, int tag, void *ptr); ! 49: void Z_Free (void *ptr); ! 50: void Z_FreeTags (int lowtag, int hightag); ! 51: void Z_DumpHeap (int lowtag, int hightag); ! 52: void Z_FileDumpHeap (FILE *f); ! 53: void Z_CheckHeap (void); ! 54: void Z_ChangeTag2 (void *ptr, int tag); ! 55: int Z_FreeMemory (void); ! 56: ! 57: ! 58: typedef struct memblock_s ! 59: { ! 60: int size; // including the header and possibly tiny fragments ! 61: void** user; // NULL if a free block ! 62: int tag; // purgelevel ! 63: int id; // should be ZONEID ! 64: struct memblock_s* next; ! 65: struct memblock_s* prev; ! 66: } memblock_t; ! 67: ! 68: // ! 69: // This is used to get the local FILE:LINE info from CPP ! 70: // prior to really call the function in question. ! 71: // ! 72: #define Z_ChangeTag(p,t) \ ! 73: { \ ! 74: if (( (memblock_t *)( (byte *)(p) - sizeof(memblock_t)))->id!=0x1d4a11) \ ! 75: I_Error("Z_CT at "__FILE__":%i",__LINE__); \ ! 76: Z_ChangeTag2(p,t); \ ! 77: }; ! 78: ! 79: ! 80: ! 81: #endif ! 82: //----------------------------------------------------------------------------- ! 83: // ! 84: // $Log:$ ! 85: // ! 86: //-----------------------------------------------------------------------------
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.