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