00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ArmageTron_tMemManager_H
00029 #define ArmageTron_tMemManager_H
00030
00031 #include "aa_config.h"
00032 #include <new>
00033
00034 #ifdef HAVE_STDLIB
00035 #include <stdlib.h>
00036 #endif
00037
00038 #ifdef HAVE_LIBEFENCE
00039 #include <efence.h>
00040 #ifdef DONTUSEMEMMANAGER
00041 #include <efencepp.h>
00042 #endif
00043 #endif
00044
00045 #ifndef _MSC_VER
00046 #ifndef _cdecl
00047 #define _cdecl
00048 #endif
00049 #endif
00050
00051 #include <stdlib.h>
00052
00053 class tMemManBase{
00054 public:
00055 static void Check();
00056 static void Profile();
00057 };
00058
00059 #ifdef WIN32
00060 #ifdef DEBUG
00061
00062 #endif
00063 #endif
00064
00065 #ifdef _MSC_VER
00066
00067
00068 #define THROW_BADALLOC
00069 #define THROW_NOTHING
00070 #else
00071 #define THROW_BADALLOC throw (std::bad_alloc)
00072 #define THROW_NOTHING throw ()
00073 #endif
00074
00075
00076 #ifndef DONTUSEMEMMANAGER
00077
00078 #ifndef NO_MALLOC_REPLACEMENT
00079
00080
00081 #include <ios>
00082
00083
00084 #define malloc(SIZE) static_cast<void *>(tNEW(char)[SIZE])
00085 #define calloc(ELEMCOUNT, ELEMSIZE) static_cast<void *>(tNEW(char)[(ELEMCOUNT)*(ELEMSIZE)])
00086 #define free(BASEADR) delete[] (reinterpret_cast< char* >(BASEADR))
00087 #define realloc(BASEADR, NEWSIZE) realloc not defined
00088
00089
00090 #define strdup(ADR) tStrDup(ADR)
00091
00092
00093 char * tStrDup( char const * s );
00094
00095
00096 void * real_calloc( size_t nmemb, size_t size );
00097 void * real_malloc( size_t size );
00098 void real_free( void * ptr );
00099 void * real_realloc( void * ptr, size_t size );
00100 char * real_strdup( char const * ptr );
00101 void * real_mmove( void * ptr, size_t size );
00102 char * real_strmove( char * ptr );
00103 #endif
00104
00105
00106 void* _cdecl operator new (size_t size) THROW_BADALLOC;
00107 void _cdecl operator delete (void *ptr) THROW_NOTHING;
00108 void operator delete (void *ptr,bool keep) THROW_NOTHING;
00109 void* operator new (size_t size,const char *classn,const char *file,int line) THROW_BADALLOC;
00110 void operator delete (void *ptr,const char *classn, const char *file,int line) THROW_NOTHING;
00111 void* operator new[] (size_t size) THROW_BADALLOC;
00112 void operator delete[] (void *ptr) THROW_NOTHING;
00113 void* operator new[] (size_t size,const char *classn,const char *file,int line) THROW_BADALLOC;
00114 void operator delete[] (void *ptr,const char *classname,const char *file,int line) THROW_NOTHING;
00115
00116 void * operator new(
00117 size_t cb,
00118 int nBlockUse,
00119 const char * szFileName,
00120 int nLine
00121 );
00122
00123 void operator delete(
00124 void * ptr,
00125 int nBlockUse,
00126 const char * szFileName,
00127 int nLine
00128 );
00129
00130 #define tNEW(x) new(#x,__FILE__,__LINE__) x
00131
00132 #define tMEMMANAGER(classname) public:void *operator new(size_t s){return tMemMan::Alloc(s); } void operator delete(void *p){ if (p) tMemMan::Dispose(p); }
00133 #else
00134 #define tNEW(x) new x
00135 #define tMEMMANAGER(classname)
00136
00137
00138 #define real_malloc(SIZE) malloc(SIZE)
00139 #define real_calloc(ELEMCOUNT, ELEMSIZE) calloc(ELEMCOUNT, ELEMSIZE)
00140 #define real_free(BASEADR) free(BASEADR)
00141 #define real_realloc(BASEADR, NEWSIZE) realloc(BASEADR, NEWSIZE)
00142 #define real_strdup( PTR ) strdup(PTR)
00143 #define real_mmove( BASEADR, SIZE ) (BASEADR)
00144 #define real_strmove( BASEADR ) (BASEADR)
00145
00146 #endif
00147
00148 #endif