alloc.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 #  include <config.h>
00021 #endif
00022 
00023 #ifndef ALPHA_LINUX_CXX
00024 #  include <cstdlib>
00025 #  include <cstdio>
00026 #endif
00027 #include <new>
00028 #if 0
00029 // Some people are having trouble with this
00030 #include <pthread_alloc>  // This allocator defines memset (we think)
00031 #else
00032 #ifndef ALPHA_LINUX_CXX
00033 #  include <cstring>
00034 #endif
00035 #endif
00036 
00037 unsigned long exult_mem = 0L;   // Keep track of total memory allocated
00038 
00039 #ifdef WANT_ALTERNATE_ALLOCATOR
00040 #ifdef POISON_ALLOCATED_BLOCKS
00041 #undef INITIALISE_ALLOCATED_BLOCKS
00042 #define INITIALISE_ALLOCATED_BLOCKS 0xf1
00043 #endif
00044 
00045 void *operator new (size_t) throw (std::bad_alloc);
00046 void *operator new[] (size_t) throw (std::bad_alloc);
00047 
00048 void  *operator new(size_t n) throw (std::bad_alloc)
00049 {
00050   void  *r;
00051   r=malloc(n);
00052   if(!r)
00053     throw std::bad_alloc();
00054 #ifdef INITIALISE_ALLOCATED_BLOCKS
00055   memset(r,INITIALISE_ALLOCATED_BLOCKS,n);
00056 #endif
00057   exult_mem += n;
00058   return r;
00059 }
00060 
00061 void  *operator new[](size_t n) throw (std::bad_alloc)
00062 {
00063   void  *r=malloc(n);
00064   if(!r)
00065     throw std::bad_alloc();
00066 #ifdef INITIALISE_ALLOCATED_BLOCKS
00067   memset(r,INITIALISE_ALLOCATED_BLOCKS,n);
00068 #endif
00069   exult_mem += n;
00070   return r;
00071 }
00072 
00073 void  operator delete(void *p) throw()
00074 {
00075   if(p)
00076     free(p);
00077   // C++ doesn't throw if it's asked to delete
00078   // a null pointer
00079 }
00080 void  operator delete[](void *p) throw()
00081 {
00082   if(p)
00083     free(p);
00084 }
00085 
00086 #endif

Generated on Mon Jul 9 14:42:40 2007 for ExultEngine by  doxygen 1.5.1