00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef COMMON_MEM_H
00021 #define COMMON_MEM_H
00022
00028 #include <common/ac/stddef.h>
00029 #include <common/ac/new.h>
00030 #include <common/main.h>
00031
00046 void *mem_alloc(size_t nbytes);
00047
00048 #ifdef DMALLOC
00049 void *dmem_alloc(const char *file, int line, size_t nbytes);
00050 #define mem_alloc(nbytes) dmem_alloc(__FILE__, __LINE__, (nbytes))
00051 #endif
00052
00067 void *mem_alloc_clear(size_t nbytes);
00068 #ifdef DMALLOC
00069 void *dmem_alloc_clear(const char *file, int line, size_t nbytes);
00070 #define mem_alloc_clear(nbytes) dmem_alloc_clear(__FILE__, __LINE__, (nbytes))
00071 #endif
00072
00073
00074 void *mem_change_size(void *, size_t);
00075 #ifdef DMALLOC
00076 void *dmem_change_size(const char *file, int line, void *p,
00077 size_t nbytes);
00078 #define mem_change_size(p, nbytes) \
00079 dmem_change_size(__FILE__, __LINE__, (p), (nbytes))
00080 #endif
00081
00082 void mem_free(void *);
00083 #ifdef DMALLOC
00084 void dmem_free(const char *file, int line, void *p);
00085 #define mem_free(p) dmem_free(__FILE__, __LINE__, (p))
00086 #endif
00087
00088
00099 char *mem_copy_string(const char *arg);
00100 #ifdef DMALLOC
00101 char *dmem_copy_string(const char *file, int line, const char *p);
00102 #define mem_copy_string(p) dmem_copy_string(__FILE__, __LINE__, (p))
00103 #endif
00104
00105
00118 char *mem_copy_string(const char *arg, size_t len);
00119 #ifdef DMALLOC
00120 char *dmem_copy_string(const char *file, int line,
00121 const char *p, size_t len);
00122 #undef mem_copy_string
00123 #define mem_copy_string(p, ...) \
00124 dmem_copy_string(__FILE__, __LINE__, (p), ## __VA_ARGS__)
00125 #endif
00126
00127 #if HAVE_HEADER_NEW || HAVE_NEW_H
00128 #define THROW_BAD_ALLOC throw(std::bad_alloc)
00129 #else
00130 #define THROW_BAD_ALLOC
00131 #endif
00132
00133 #ifndef DMALLOC
00134 void *operator new(size_t nbytes) THROW_BAD_ALLOC;
00135 #else
00136 void *operator new(size_t nbytes, const char *file, int line)
00137 THROW_BAD_ALLOC;
00138 #endif
00139
00140 #ifndef DMALLOC
00141 void *operator new[](size_t nbytes) THROW_BAD_ALLOC;
00142 #else
00143 void *operator new[](size_t nbytes, const char *file, int line)
00144 THROW_BAD_ALLOC;
00145 #endif
00146
00147 #ifndef DMALLOC
00148 void operator delete(void *ptr) throw();
00149 #else
00150 void operator delete(void *ptr, const char *file, int line) throw();
00151 #endif
00152
00153 #ifndef DMALLOC
00154 void operator delete[](void *ptr) throw();
00155 #else
00156 void operator delete[](void *ptr, const char *file, int line) throw();
00157 #endif
00158
00159 #if HAVE_HEADER_NEW || HAVE_NEW_H
00160
00161 #ifndef DMALLOC
00162 void *operator new(size_t nbytes, std::nothrow_t &) throw();
00163 #else
00164 void *operator new(size_t nbytes, std::nothrow_t &, const char *file,
00165 int line) throw();
00166 #endif
00167
00168 #ifndef DMALLOC
00169 void *operator new[](size_t nbytes, std::nothrow_t &) throw();
00170 #else
00171 void *operator new[](size_t nbytes, std::nothrow_t &, const char *file,
00172 int line) throw();
00173 #endif
00174
00175 #ifndef DMALLOC
00176 void operator delete(void *ptr, std::nothrow_t const &) throw();
00177 #else
00178 void operator delete(void *ptr, std::nothrow_t const &, const char *file,
00179 int line) throw();
00180 #endif
00181
00182 #ifndef DMALLOC
00183 void operator delete[](void *ptr, std::nothrow_t const &) throw();
00184 #else
00185 void operator delete[](void *ptr, std::nothrow_t const &, const char *file,
00186 int line) throw();
00187 #endif
00188
00189 #ifdef DMALLOC
00190 #define new new(__FILE__, __LINE__)
00191
00192 #endif
00193
00194 #endif
00195
00197 #endif // COMMON_MEM_H