3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
10
This program is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
***************************************************************************
28
#ifndef ArmageTron_tMemManager_H
29
#define ArmageTron_tMemManager_H
40
#ifdef DONTUSEMEMMANAGER
56
static void Profile();
61
//#define DONTUSEMEMMANAGER
66
//#define THROW_BADALLOC _THROW1(std::bad_alloc)
67
//#define THROW_NOTHING _THROW0()
68
#define THROW_BADALLOC
71
#define THROW_BADALLOC throw (std::bad_alloc)
72
#define THROW_NOTHING throw ()
76
#ifndef DONTUSEMEMMANAGER
78
#ifndef NO_MALLOC_REPLACEMENT
80
// the following include file was found to disable the macros again
83
// macros replacing C memory management
84
#define malloc(SIZE) static_cast<void *>(tNEW(char)[SIZE])
85
#define calloc(ELEMCOUNT, ELEMSIZE) static_cast<void *>(tNEW(char)[(ELEMCOUNT)*(ELEMSIZE)])
86
#define free(BASEADR) delete[] (reinterpret_cast< char* >(BASEADR))
87
#define realloc(BASEADR, NEWSIZE) realloc not defined
89
// and other allocating functions
90
#define strdup(ADR) tStrDup(ADR)
93
char * tStrDup( char const * s );
95
// call the real malloc functions
96
void * real_calloc( size_t nmemb, size_t size ); // call calloc
97
void * real_malloc( size_t size ); // call malloc
98
void real_free( void * ptr ); // call free
99
void * real_realloc( void * ptr, size_t size ); // call realloc
100
char * real_strdup( char const * ptr ); // calls strdup
101
void * real_mmove( void * ptr, size_t size ); // take memory allocated by real_malloc or a C library function and move to managed memory
102
char * real_strmove( char * ptr ); // take C string allocated by real_malloc or a C library function and move to managed memory
106
void* _cdecl operator new (size_t size) THROW_BADALLOC;
107
void _cdecl operator delete (void *ptr) THROW_NOTHING;
108
void operator delete (void *ptr,bool keep) THROW_NOTHING;
109
void* operator new (size_t size,const char *classn,const char *file,int line) THROW_BADALLOC;
110
void operator delete (void *ptr,const char *classn, const char *file,int line) THROW_NOTHING;
111
void* operator new[] (size_t size) THROW_BADALLOC;
112
void operator delete[] (void *ptr) THROW_NOTHING;
113
void* operator new[] (size_t size,const char *classn,const char *file,int line) THROW_BADALLOC;
114
void operator delete[] (void *ptr,const char *classname,const char *file,int line) THROW_NOTHING;
119
const char * szFileName,
123
void operator delete(
126
const char * szFileName,
130
#define tNEW(x) new(#x,__FILE__,__LINE__) x
132
#define tMEMMANAGER(classname) public:void *operator new(size_t s){return tMemMan::Alloc(s); } void operator delete(void *p){ if (p) tMemMan::Dispose(p); }
134
#define tNEW(x) new x
135
#define tMEMMANAGER(classname)
137
// just direct to the real malloc functions
138
#define real_malloc(SIZE) malloc(SIZE)
139
#define real_calloc(ELEMCOUNT, ELEMSIZE) calloc(ELEMCOUNT, ELEMSIZE)
140
#define real_free(BASEADR) free(BASEADR)
141
#define real_realloc(BASEADR, NEWSIZE) realloc(BASEADR, NEWSIZE)
142
#define real_strdup( PTR ) strdup(PTR)
143
#define real_mmove( BASEADR, SIZE ) (BASEADR)
144
#define real_strmove( BASEADR ) (BASEADR)