mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-24 21:48:08 -04:00
dtool: Improve memory usage tracking without USE_DELETED_CHAIN
Now all classes that use ALLOC_DELETED_CHAIN participate in memory usage tracking even when USE_DELETED_CHAIN is not set (as long as DO_MEMORY_USAGE is set)
This commit is contained in:
parent
d65e46e7b7
commit
3f45a8e367
@ -122,6 +122,50 @@ public:
|
||||
#define ALLOC_DELETED_CHAIN_DEF(Type) \
|
||||
DeletedChain< Type > Type::_deleted_chain;
|
||||
|
||||
#elif defined(DO_MEMORY_USAGE)
|
||||
|
||||
#define ALLOC_DELETED_CHAIN(Type) \
|
||||
inline void *operator new(size_t size) RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT) { \
|
||||
void *ptr = PANDA_MALLOC_SINGLE(size); \
|
||||
get_type_handle(Type).inc_memory_usage(TypeHandle::MC_singleton, sizeof(Type)); \
|
||||
return ptr; \
|
||||
} \
|
||||
inline void *operator new(size_t size, void *ptr) { \
|
||||
(void) size; \
|
||||
return ptr; \
|
||||
} \
|
||||
inline void operator delete(void *ptr) { \
|
||||
if (ptr != nullptr) { \
|
||||
get_type_handle(Type).dec_memory_usage(TypeHandle::MC_singleton, sizeof(Type)); \
|
||||
PANDA_FREE_SINGLE(ptr); \
|
||||
} \
|
||||
} \
|
||||
inline void operator delete(void *, void *) { \
|
||||
} \
|
||||
inline void *operator new[](size_t size) RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT) { \
|
||||
void *ptr = PANDA_MALLOC_SINGLE(size); \
|
||||
get_type_handle(Type).inc_memory_usage(TypeHandle::MC_array, sizeof(Type)); \
|
||||
return ptr; \
|
||||
} \
|
||||
inline void *operator new[](size_t size, void *ptr) { \
|
||||
(void) size; \
|
||||
return ptr; \
|
||||
} \
|
||||
inline void operator delete[](void *ptr) { \
|
||||
if (ptr != nullptr) { \
|
||||
get_type_handle(Type).dec_memory_usage(TypeHandle::MC_array, sizeof(Type)); \
|
||||
PANDA_FREE_SINGLE(ptr); \
|
||||
} \
|
||||
} \
|
||||
inline void operator delete[](void *, void *) { \
|
||||
} \
|
||||
inline static bool validate_ptr(const void *ptr) { \
|
||||
return (ptr != nullptr); \
|
||||
}
|
||||
|
||||
#define ALLOC_DELETED_CHAIN_DECL(Type) ALLOC_DELETED_CHAIN(Type)
|
||||
#define ALLOC_DELETED_CHAIN_DEF(Type)
|
||||
|
||||
#else // USE_DELETED_CHAIN
|
||||
|
||||
#define ALLOC_DELETED_CHAIN(Type) \
|
||||
|
Loading…
x
Reference in New Issue
Block a user