25 #ifdef DO_MEMORY_USAGE 26 assert((
int)memory_class >= 0 && (
int)memory_class < (
int)MC_limit);
27 if ((*
this) == TypeHandle::none()) {
31 assert(rnode !=
nullptr);
34 #endif // DO_MEMORY_USAGE 44 #ifdef DO_MEMORY_USAGE 46 assert((
int)memory_class >= 0 && (
int)memory_class < (
int)MC_limit);
48 if ((*
this) != TypeHandle::none()) {
50 assert(rnode !=
nullptr);
51 AtomicAdjust::add(rnode->_memory_usage[memory_class], (AtomicAdjust::Integer)size);
54 if (rnode->_memory_usage[memory_class] < 0) {
55 std::cerr <<
"Memory usage overflow for type " << rnode->_name <<
".\n";
59 #endif // DO_MEMORY_USAGE 68 #ifdef DO_MEMORY_USAGE 70 assert((
int)memory_class >= 0 && (
int)memory_class < (
int)MC_limit);
72 if ((*
this) != TypeHandle::none()) {
74 assert(rnode !=
nullptr);
75 AtomicAdjust::add(rnode->_memory_usage[memory_class], -(AtomicAdjust::Integer)size);
78 assert(rnode->_memory_usage[memory_class] >= 0);
80 #endif // DO_MEMORY_USAGE 89 TAU_PROFILE(
"TypeHandle:allocate_array()",
" ", TAU_USER);
91 void *ptr = PANDA_MALLOC_ARRAY(size);
92 #ifdef DO_MEMORY_USAGE 93 if ((*
this) != TypeHandle::none()) {
96 assert(size <= alloc_size);
99 assert(rnode !=
nullptr);
100 AtomicAdjust::add(rnode->_memory_usage[MC_array], (AtomicAdjust::Integer)alloc_size);
101 if (rnode->_memory_usage[MC_array] < 0) {
102 std::cerr <<
"Memory usage overflow for type " << rnode->_name <<
".\n";
106 #endif // DO_MEMORY_USAGE 116 TAU_PROFILE(
"TypeHandle:reallocate_array()",
" ", TAU_USER);
118 #ifdef DO_MEMORY_USAGE 120 void *new_ptr = PANDA_REALLOC_ARRAY(old_ptr, size);
122 if ((*
this) != TypeHandle::none()) {
126 assert(rnode !=
nullptr);
127 AtomicAdjust::add(rnode->_memory_usage[MC_array], (AtomicAdjust::Integer)new_size - (AtomicAdjust::Integer)old_size);
128 assert(rnode->_memory_usage[MC_array] >= 0);
131 void *new_ptr = PANDA_REALLOC_ARRAY(old_ptr, size);
142 TAU_PROFILE(
"TypeHandle:deallocate_array()",
" ", TAU_USER);
144 #ifdef DO_MEMORY_USAGE 146 if ((*
this) != TypeHandle::none()) {
148 assert(rnode !=
nullptr);
149 AtomicAdjust::add(rnode->_memory_usage[MC_array], -(AtomicAdjust::Integer)alloc_size);
150 assert(rnode->_memory_usage[MC_array] >= 0);
152 #endif // DO_MEMORY_USAGE 153 PANDA_FREE_ARRAY(ptr);
160 PyObject *TypeHandle::
161 get_python_type()
const {
163 if (rnode !=
nullptr) {
176 if (legal_vals.find(_index) != legal_vals.end()) {
191 operator << (std::ostream &out, TypeHandle::MemoryClass mem_class) {
193 case TypeHandle::MC_singleton:
194 return out <<
"singleton";
196 case TypeHandle::MC_array:
197 return out <<
"array";
199 case TypeHandle::MC_deleted_chain_active:
200 return out <<
"deleted_chain_active";
202 case TypeHandle::MC_deleted_chain_inactive:
203 return out <<
"deleted_chain_inactive";
205 case TypeHandle::MC_limit:
206 return out <<
"limit";
210 <<
"**invalid TypeHandle::MemoryClass (" << (int)mem_class
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_best_parent_from_Set(const std::set< int > &legal_vals) const
Return the Index of the BEst fit Classs from a set.
PyObject * get_python_type() const
Returns the Python type object associated with this node.
void deallocate_array(void *ptr)
Deallocates memory, subtracting it from the total amount of memory allocated for this type.
static Integer add(Integer &var, Integer delta)
Atomically computes var += delta.
This is a single entry in the TypeRegistry.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void inc_memory_usage(MemoryClass memory_class, size_t size)
Adds the indicated amount to the record for the total allocated memory for objects of this type.
static Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.
size_t get_memory_usage(MemoryClass memory_class) const
Returns the total allocated memory used by objects of this type, for the indicated memory class.
get_parent_class
Returns the nth parent class of this type.
static TypeRegistry * ptr()
Returns the pointer to the global TypeRegistry object.
void * reallocate_array(void *ptr, size_t size)
Reallocates memory, adjusting the total amount of memory allocated for this type.
void * allocate_array(size_t size)
Allocates memory, adding it to the total amount of memory allocated for this type.
get_num_parent_classes
Returns the number of parent classes that this type is known to have.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void dec_memory_usage(MemoryClass memory_class, size_t size)
Subtracts the indicated amount from the record for the total allocated memory for objects of this typ...
static size_t get_ptr_size(void *ptr)
Given a pointer that was returned by a MemoryHook allocation, returns the number of bytes that were a...