mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
hey, I overlooked heap_alloc_array() et al
This commit is contained in:
parent
0ce0196027
commit
79e60e25ec
@ -254,6 +254,116 @@ heap_free_single(void *ptr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: MemoryUsage::heap_alloc_array
|
||||||
|
// Access: Public, Virtual
|
||||||
|
// Description: Allocates a block of memory from the heap, similar to
|
||||||
|
// malloc(). This will never return NULL; it will abort
|
||||||
|
// instead if memory is not available.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void *MemoryUsage::
|
||||||
|
heap_alloc_array(size_t size) {
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
|
if (_recursion_protect) {
|
||||||
|
ptr = MemoryHook::heap_alloc_array(size);
|
||||||
|
if (express_cat.is_spam()) {
|
||||||
|
express_cat.spam()
|
||||||
|
<< "Allocating array pointer " << (void *)ptr
|
||||||
|
<< " during recursion protect.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (_track_memory_usage) {
|
||||||
|
ptr = MemoryHook::heap_alloc_array(size);
|
||||||
|
/*
|
||||||
|
if (express_cat.is_spam()) {
|
||||||
|
express_cat.spam()
|
||||||
|
<< "Allocating array pointer " << (void *)ptr
|
||||||
|
<< " of size " << size << ".\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
get_global_ptr()->ns_record_void_pointer(ptr, size);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ptr = MemoryHook::heap_alloc_array(size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: MemoryUsage::heap_realloc_array
|
||||||
|
// Access: Public, Virtual
|
||||||
|
// Description: Resizes a block of memory previously returned from
|
||||||
|
// heap_alloc_array.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void *MemoryUsage::
|
||||||
|
heap_realloc_array(void *ptr, size_t size) {
|
||||||
|
if (_recursion_protect) {
|
||||||
|
ptr = MemoryHook::heap_realloc_array(ptr, size);
|
||||||
|
if (express_cat.is_spam()) {
|
||||||
|
express_cat.spam()
|
||||||
|
<< "Reallocating array pointer " << (void *)ptr
|
||||||
|
<< " during recursion protect.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (_track_memory_usage) {
|
||||||
|
get_global_ptr()->ns_remove_void_pointer(ptr);
|
||||||
|
ptr = MemoryHook::heap_realloc_array(ptr, size);
|
||||||
|
/*
|
||||||
|
if (express_cat.is_spam()) {
|
||||||
|
express_cat.spam()
|
||||||
|
<< "Reallocating array pointer " << (void *)ptr
|
||||||
|
<< " to size " << size << ".\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
get_global_ptr()->ns_record_void_pointer(ptr, size);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ptr = MemoryHook::heap_realloc_array(ptr, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: MemoryUsage::heap_free_array
|
||||||
|
// Access: Public, Virtual
|
||||||
|
// Description: Releases a block of memory previously allocated via
|
||||||
|
// heap_alloc_array.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void MemoryUsage::
|
||||||
|
heap_free_array(void *ptr) {
|
||||||
|
if (_recursion_protect) {
|
||||||
|
if (express_cat.is_spam()) {
|
||||||
|
express_cat.spam()
|
||||||
|
<< "Deleting pointer " << (void *)ptr
|
||||||
|
<< " during recursion protect.\n";
|
||||||
|
}
|
||||||
|
MemoryHook::heap_free_array(ptr);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (_track_memory_usage) {
|
||||||
|
/*
|
||||||
|
if (express_cat.is_spam()) {
|
||||||
|
express_cat.spam()
|
||||||
|
<< "Removing pointer " << (void *)ptr << "\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
ns_remove_void_pointer(ptr);
|
||||||
|
MemoryHook::heap_free_array(ptr);
|
||||||
|
} else {
|
||||||
|
MemoryHook::heap_free_array(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: MemoryUsage::mark_pointer
|
// Function: MemoryUsage::mark_pointer
|
||||||
// Access: Public, Virtual
|
// Access: Public, Virtual
|
||||||
|
@ -50,6 +50,11 @@ public:
|
|||||||
public:
|
public:
|
||||||
virtual void *heap_alloc_single(size_t size);
|
virtual void *heap_alloc_single(size_t size);
|
||||||
virtual void heap_free_single(void *ptr);
|
virtual void heap_free_single(void *ptr);
|
||||||
|
|
||||||
|
virtual void *heap_alloc_array(size_t size);
|
||||||
|
virtual void *heap_realloc_array(void *ptr, size_t size);
|
||||||
|
virtual void heap_free_array(void *ptr);
|
||||||
|
|
||||||
virtual void mark_pointer(void *ptr, size_t orig_size, ReferenceCount *ref_ptr);
|
virtual void mark_pointer(void *ptr, size_t orig_size, ReferenceCount *ref_ptr);
|
||||||
|
|
||||||
#if (defined(WIN32_VC) || defined(WIN64_VC)) && defined(_DEBUG)
|
#if (defined(WIN32_VC) || defined(WIN64_VC)) && defined(_DEBUG)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user