00001
00020 #ifndef MEMRY_H
00021 #define MEMRY_H
00022
00023 #include <stddef.h>
00024 #include "host.h"
00025
00026 #define JUSTCHECKS 0
00027 #define MEMCHECKS 1
00028 #define FULLMEMCHECKS 2
00029
00030 #ifdef __MSW32__
00031 #define NEWDELETE \
00032 void *operator new( \
00033 size_t size, \
00034 const char* file=NULL, \
00035 INT32 line=0) \
00036 {\
00037 return alloc_struct(size); \
00038 }\
00039 \
00040 void operator delete( \
00041 void *deadstruct, \
00042 size_t size) \
00043 {\
00044 free_struct(deadstruct,size); \
00045 }\
00046
00047 #define NEWDELETE2(name) \
00048 void *operator new( \
00049 size_t size, \
00050 const char* file=NULL, \
00051 INT32 line=0) \
00052 {\
00053 return alloc_struct(size,#name); \
00054 }\
00055 \
00056 void operator delete( \
00057 void *deadstruct, \
00058 size_t size) \
00059 {\
00060 free_struct(deadstruct,size,#name); \
00061 }\
00062
00063
00064 #undef NEWDELETE
00065 #define NEWDELETE
00066 #undef NEWDELETE2
00067 #define NEWDELETE2(name)
00068
00069 #else
00070 #define NEWDELETE \
00071 void *operator new( \
00072 size_t size) \
00073 {\
00074 return alloc_struct(size); \
00075 }\
00076 \
00077 void operator delete( \
00078 void *deadstruct, \
00079 size_t size) \
00080 {\
00081 free_struct(deadstruct,size); \
00082 }\
00083
00084 #define NEWDELETE2(name) \
00085 void *operator new( \
00086 size_t size) \
00087 {\
00088 return alloc_struct(size,#name); \
00089 }\
00090 \
00091 void operator delete( \
00092 void *deadstruct, \
00093 size_t size) \
00094 {\
00095 free_struct(deadstruct,size,#name); \
00096 }\
00097
00098 #endif
00099
00103 #define ALLOC_2D_ARRAY(x,y,mem,ptrs,type) \
00104 { \
00105 INT32 TMP_i; \
00106 mem=(type*)alloc_mem((x)*(y)*sizeof(type)); \
00107 ptrs=(type**)alloc_mem((x)*sizeof(type*)); \
00108 for (TMP_i=0;TMP_i<(x);TMP_i++)\
00109 ptrs[TMP_i]=mem+(y)*TMP_i; \
00110 } \
00111
00112
00115 #define FREE_2D_ARRAY(mem,ptrs) \
00116 { \
00117 free_mem(mem); \
00118 free_mem(ptrs); \
00119 } \
00120
00121
00125 #define ALLOC_BIG_2D_ARRAY(x,y,mem,ptrs,type) \
00126 { \
00127 INT32 TMP_i; \
00128 mem=(type*)alloc_big_mem((x)*(y)*sizeof(type)); \
00129 ptrs=(type**)alloc_big_mem((x)*sizeof(type*)); \
00130 for (TMP_i=0;TMP_i<(x);TMP_i++)\
00131 ptrs[TMP_i]=mem+(y)*TMP_i; \
00132 } \
00133
00134
00137 #define FREE_BIG_2D_ARRAY(mem,ptrs) \
00138 { \
00139 free_big_mem(mem); \
00140 free_big_mem(ptrs); \
00141 } \
00142
00143 extern DLLSYM void check_mem(
00144 const char *string,
00145 INT8 level
00146 );
00147
00148 extern DLLSYM char *alloc_string(INT32 count
00149 );
00150 extern DLLSYM void free_string(
00151 char *string
00152 );
00153
00154 extern DLLSYM void *alloc_struct (
00155 INT32 count,
00156 const char *name = NULL
00157 );
00158 extern DLLSYM void free_struct (
00159 void *deadstruct,
00160 INT32 count,
00161 const char *name = NULL
00162 );
00163 extern DLLSYM void *alloc_mem_p(
00164 INT32 count
00165 );
00166 extern DLLSYM void *alloc_mem(
00167 INT32 count
00168 );
00169
00170 extern DLLSYM void *alloc_big_mem(INT32 count
00171 );
00172
00173 extern DLLSYM void *alloc_big_zeros(INT32 count
00174 );
00175 extern DLLSYM void free_mem(
00176 void *oldchunk
00177 );
00178 extern DLLSYM void free_big_mem(
00179 void *oldchunk
00180 );
00181 #endif