src/tools/tMemManager.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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 //#define DONTUSEMEMMANAGER
00062 #endif
00063 #endif
00064 
00065 #ifdef _MSC_VER
00066 //#define THROW_BADALLOC _THROW1(std::bad_alloc)
00067 //#define THROW_NOTHING  _THROW0()
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 // the following include file was found to disable the macros again
00081 #include <ios>
00082 
00083 // macros replacing C memory management
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 // and other allocating functions
00090 #define strdup(ADR)  tStrDup(ADR)
00091 
00092 // implementation
00093 char * tStrDup( char const * s );
00094 
00095 // call the real malloc functions
00096 void * real_calloc( size_t nmemb, size_t size ); // call calloc
00097 void * real_malloc( size_t size );               // call malloc
00098 void   real_free( void * ptr );                  // call free
00099 void * real_realloc( void * ptr, size_t size );  // call realloc
00100 char * real_strdup( char const * ptr );          // calls strdup
00101 void * real_mmove( void * ptr, size_t size );    // take memory allocated by real_malloc or a C library function and move to managed memory
00102 char * real_strmove( char * ptr );               // take C string allocated by real_malloc or a C library function and move to managed memory
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 // just direct to the real malloc functions
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

Generated on Sat Mar 15 22:56:01 2008 for Armagetron Advanced by  doxygen 1.5.4