| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/lib/mem.h $ |
| 21 | * $Revision: 18 $ |
| 22 | * $Date: 3/20/00 12:26p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * Memory header. |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/lib/mem.h $ |
| 28 | * |
| 29 | * 18 3/20/00 12:26p Matt |
| 30 | * Merge of Duane's post-1.3 changes. |
| 31 | * Added declaration |
| 32 | * |
| 33 | * 17 10/21/99 9:27p Jeff |
| 34 | * B.A. Macintosh code merge |
| 35 | * |
| 36 | * 16 8/10/99 5:12p Jeff |
| 37 | * added a debug function to dump the current state of the mem library to |
| 38 | * file |
| 39 | * |
| 40 | * 15 3/15/99 11:24a Kevin |
| 41 | * Improved memory leak detection for mem_strdup and turned on debugging |
| 42 | * |
| 43 | * 14 10/13/98 3:42p Kevin |
| 44 | * bug fixes |
| 45 | * |
| 46 | * 13 10/13/98 9:25a Kevin |
| 47 | * |
| 48 | * 12 10/12/98 8:39p Kevin |
| 49 | * removed mprintf's and fixed some smallish bugs |
| 50 | * |
| 51 | * 11 10/12/98 11:54a Kevin |
| 52 | * |
| 53 | * 10 10/12/98 10:55a Kevin |
| 54 | * Don't use memory lib for editor currently |
| 55 | * |
| 56 | * 9 10/12/98 10:22a Samir |
| 57 | * made mem_strdup take a const char pointer. |
| 58 | * |
| 59 | * 8 10/09/98 3:32p Kevin |
| 60 | * New memory library |
| 61 | * |
| 62 | * 7 10/08/98 4:24p Kevin |
| 63 | * Changed code to comply with memory library usage. Always use mem_malloc |
| 64 | * , mem_free and mem_strdup |
| 65 | * |
| 66 | * 6 10/08/98 2:40p Kevin |
| 67 | * |
| 68 | * 5 7/31/98 5:44p Samir |
| 69 | * improved memory debugging. |
| 70 | * |
| 71 | * $NoKeywords: $ |
| 72 | */ |
| 73 | |
| 74 | #ifndef MEM_H |
| 75 | #define MEM_H |
| 76 | |
| 77 | // Memory management debugging |
| 78 | #ifdef MEM_USE_RTL |
| 79 | #define mem_malloc(d) malloc(d) // Use this if your going to run BoundsChecker |
| 80 | #define mem_free(d) free(d) |
| 81 | #define mem_strdup(d) strdup(d) |
| 82 | #define mem_size(d) mem_size_sub(d) |
| 83 | #define mem_realloc(d, e) realloc(d, e) |
| 84 | #else |
| 85 | // Use this if your going to NOT run BoundsChecker |
| 86 | #define mem_malloc(d) mem_malloc_sub(d, __FILE__, __LINE__) |
| 87 | #define mem_free(d) mem_free_sub(d) |
| 88 | #define mem_strdup(d) mem_strdup_sub(d, __FILE__, __LINE__) |
| 89 | #define mem_size(d) mem_size_sub(d) |
| 90 | #define mem_realloc(d, e) mem_realloc_sub(d, e) |
| 91 | #endif |
| 92 | |
| 93 | extern bool Mem_low_memory_mode; |
| 94 | extern bool Mem_superlow_memory_mode; // DAJ |
| 95 | |
| 96 | // use if you want to manually print out a memory error |
| 97 | #define mem_error() mem_error_msg(__FILE__, __LINE__) |
| 98 | |
| 99 | // initializes memory library. |
| 100 | void mem_Init(); |
| 101 | |
| 102 | // shutsdown memory |
| 103 | void mem_shutdown(); |
| 104 | |
| 105 | // Returns the number of dynamically allocated bytes |
| 106 | int mem_GetTotalMemoryUsed(); |
| 107 | |
| 108 | // Allocates a block of memory and returns a pointer to it |
| 109 | void *mem_malloc_sub(int size, const char *file, int line); |
| 110 | |
| 111 | // Frees a previously allocated block of memory |
| 112 | void mem_free_sub(void *memblock); |
| 113 | |
| 114 | // prints out a memory error message |
| 115 | void mem_error_msg(const char *file, int line, int size = -1); |
| 116 | |
| 117 | char *mem_strdup_sub(const char *src, const char *file, int line); |
| 118 | |
| 119 | void *mem_realloc_sub(void *memblock, int size); |
| 120 | |
| 121 | int mem_size_sub(void *memblock); |
| 122 | |
| 123 | bool mem_dumpmallocstofile(char *filename); |
| 124 | |
| 125 | void mem_heapcheck(); |
| 126 | |
| 127 | #endif |