Panda3D
memoryBase.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file memoryBase.h
10  * @author drose
11  * @date 2006-11-16
12  */
13 
14 #ifndef MEMORYBASE_H
15 #define MEMORYBASE_H
16 
17 #include "dtoolbase.h"
18 #include "memoryHook.h"
19 
20 // Place this macro within a class definition to define appropriate operator
21 // new and delete methods that hook into the MemoryInfo class to provide
22 // memory tracking. Of course, it is better simply to inherit from
23 // MemoryBase; this macro is provided to resolve problems with multiple
24 // inheritance or some such.
25 
26 #ifndef USE_MEMORY_NOWRAPPERS
27 
28 #define ALLOC_MEMORY_BASE \
29  inline void *operator new(size_t size) RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT) { \
30  return PANDA_MALLOC_SINGLE(size); \
31  } \
32  inline void *operator new(size_t size, void *ptr) { \
33  (void) size; \
34  return ptr; \
35  } \
36  inline void operator delete(void *ptr) { \
37  PANDA_FREE_SINGLE(ptr); \
38  } \
39  inline void operator delete(void *, void *) { \
40  } \
41  inline void *operator new[](size_t size) RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT) { \
42  return PANDA_MALLOC_ARRAY(size); \
43  } \
44  inline void *operator new[](size_t size, void *ptr) { \
45  (void) size; \
46  return ptr; \
47  } \
48  inline void operator delete[](void *ptr) { \
49  PANDA_FREE_ARRAY(ptr); \
50  } \
51  inline void operator delete[](void *, void *) { \
52  }
53 
54 #else // USE_MEMORY_NOWRAPPERS
55 
56 #define ALLOC_MEMORY_BASE
57 
58 #endif // USE_MEMORY_NOWRAPPERS
59 
60 /**
61  * This class is intended to be the base class of all objects in Panda that
62  * might be allocated and deleted via the new and delete operators. It
63  * redefines these operators to provide some memory tracking support.
64  *
65  * We used to try to override the global operator new and delete methods, but
66  * that seems to cause problems when including header files for C++-based
67  * system libraries (such as are found on OSX).
68  */
69 class EXPCL_DTOOL_DTOOLBASE MemoryBase {
70 public:
71  ALLOC_MEMORY_BASE;
72 };
73 
74 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class is intended to be the base class of all objects in Panda that might be allocated and delet...
Definition: memoryBase.h:69