Panda3D

memoryBase.h

00001 // Filename: memoryBase.h
00002 // Created by:  drose (16Nov06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef MEMORYBASE_H
00016 #define MEMORYBASE_H
00017 
00018 #include "dtoolbase.h"
00019 #include "memoryHook.h"
00020 
00021 // Place this macro within a class definition to define appropriate
00022 // operator new and delete methods that hook into the MemoryInfo class
00023 // to provide memory tracking.  Of course, it is better simply to
00024 // inherit from MemoryBase; this macro is provided to resolve problems
00025 // with multiple inheritance or some such.
00026 
00027 #ifndef USE_MEMORY_NOWRAPPERS
00028 
00029 #define ALLOC_MEMORY_BASE                                    \
00030   inline void *operator new(size_t size) {                   \
00031     return PANDA_MALLOC_SINGLE(size);                     \
00032   }                                                          \
00033   inline void *operator new(size_t size, void *ptr) {        \
00034     return ptr;                                              \
00035   }                                                          \
00036   inline void operator delete(void *ptr) {                   \
00037     PANDA_FREE_SINGLE(ptr);                          \
00038   }                                                          \
00039   inline void operator delete(void *ptr, void *) {           \
00040   }                                                          \
00041   inline void *operator new[](size_t size) {                 \
00042     return PANDA_MALLOC_ARRAY(size);                     \
00043   }                                                          \
00044   inline void *operator new[](size_t size, void *ptr) {      \
00045     return ptr;                                              \
00046   }                                                          \
00047   inline void operator delete[](void *ptr) {                 \
00048     PANDA_FREE_ARRAY(ptr);                          \
00049   }                                                          \
00050   inline void operator delete[](void *, void *) {            \
00051   }
00052 
00053 #else   // USE_MEMORY_NOWRAPPERS
00054 
00055 #define ALLOC_MEMORY_BASE
00056 
00057 #endif  // USE_MEMORY_NOWRAPPERS
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //       Class : MemoryBase
00061 // Description : This class is intended to be the base class of all
00062 //               objects in Panda that might be allocated and deleted
00063 //               via the new and delete operators.  It redefines these
00064 //               operators to provide some memory tracking support.
00065 //
00066 //               We used to try to override the global operator new
00067 //               and delete methods, but that seems to cause problems
00068 //               when including header files for C++-based system
00069 //               libraries (such as are found on OSX).
00070 ////////////////////////////////////////////////////////////////////
00071 class EXPCL_DTOOL MemoryBase {
00072 public:
00073   ALLOC_MEMORY_BASE;
00074 };
00075 
00076 #endif
00077 
00078 
 All Classes Functions Variables Enumerations