mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
windows niceties
This commit is contained in:
parent
5d7e726ba2
commit
ab34a7c656
@ -295,13 +295,25 @@ heap_free_array(void *ptr) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool MemoryHook::
|
bool MemoryHook::
|
||||||
heap_trim(size_t pad) {
|
heap_trim(size_t pad) {
|
||||||
|
bool trimmed = false;
|
||||||
|
|
||||||
#if defined(USE_MEMORY_DLMALLOC) || (defined(USE_MEMORY_PTMALLOC2) && !defined(linux))
|
#if defined(USE_MEMORY_DLMALLOC) || (defined(USE_MEMORY_PTMALLOC2) && !defined(linux))
|
||||||
return (dlmalloc_trim(pad) != 0);
|
|
||||||
#else
|
|
||||||
// Since malloc_trim() isn't standard C, we can't be sure it exists
|
// Since malloc_trim() isn't standard C, we can't be sure it exists
|
||||||
// on a given platform.
|
// on a given platform. But if we're using ALTERNATIVE_MALLOC, we
|
||||||
return 0;
|
// know we have dlmalloc_trim.
|
||||||
|
if (dlmalloc_trim(pad)) {
|
||||||
|
trimmed = true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
// Also, on Windows we have _heapmin().
|
||||||
|
if (_heapmin() == 0) {
|
||||||
|
trimmed = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return trimmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -97,8 +97,8 @@ is_tracking() {
|
|||||||
// Function: MemoryUsage::is_counting
|
// Function: MemoryUsage::is_counting
|
||||||
// Access: Public, Static
|
// Access: Public, Static
|
||||||
// Description: Returns true if the MemoryUsage object is currently
|
// Description: Returns true if the MemoryUsage object is currently
|
||||||
// at least counting memory (e.g. count-memory-usage is
|
// at least counting memory (e.g. this is a Windows
|
||||||
// configured #t), even if it's not fully tracking it.
|
// debug build), even if it's not fully tracking it.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE bool MemoryUsage::
|
INLINE bool MemoryUsage::
|
||||||
is_counting() {
|
is_counting() {
|
||||||
@ -213,10 +213,18 @@ INLINE size_t MemoryUsage::
|
|||||||
get_external_size() {
|
get_external_size() {
|
||||||
MemoryUsage *mu = get_global_ptr();
|
MemoryUsage *mu = get_global_ptr();
|
||||||
if (mu->_count_memory_usage) {
|
if (mu->_count_memory_usage) {
|
||||||
|
// We can only possibly know this with memory counting, which
|
||||||
|
// tracks every malloc call.
|
||||||
|
|
||||||
#if defined(USE_MEMORY_DLMALLOC) || defined(USE_MEMORY_PTMALLOC2)
|
#if defined(USE_MEMORY_DLMALLOC) || defined(USE_MEMORY_PTMALLOC2)
|
||||||
return mu->_total_size - mu->_total_heap_single_size - mu->_total_heap_array_size - mu->_interpreter_size;
|
// With alternative malloc, none of the Panda allocated memory
|
||||||
#else
|
// shows up in total_size, so anything there is either interpreter
|
||||||
|
// or external.
|
||||||
return mu->_total_size - mu->_interpreter_size;
|
return mu->_total_size - mu->_interpreter_size;
|
||||||
|
#else
|
||||||
|
// Without alternative malloc, the Panda allocated memory is also
|
||||||
|
// included in total_size, so we have to subtract it out.
|
||||||
|
return mu->_total_size - mu->_total_heap_single_size - mu->_total_heap_array_size - mu->_interpreter_size;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -336,30 +336,28 @@ win32_malloc_hook(int alloc_type, void *ptr,
|
|||||||
size_t size, int block_use, long request,
|
size_t size, int block_use, long request,
|
||||||
const unsigned char *filename, int line) {
|
const unsigned char *filename, int line) {
|
||||||
MemoryUsage *mu = get_global_ptr();
|
MemoryUsage *mu = get_global_ptr();
|
||||||
if (mu->_count_memory_usage) {
|
int increment = 0;
|
||||||
int increment = 0;
|
switch (alloc_type) {
|
||||||
switch (alloc_type) {
|
case _HOOK_ALLOC:
|
||||||
case _HOOK_ALLOC:
|
increment = size;
|
||||||
increment = size;
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case _HOOK_REALLOC:
|
|
||||||
increment = size - _msize(ptr);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case _HOOK_FREE:
|
|
||||||
increment = - ((int)_msize(ptr));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
mu->_total_size += increment;
|
case _HOOK_REALLOC:
|
||||||
|
increment = size - _msize(ptr);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case _HOOK_FREE:
|
||||||
|
increment = - ((int)_msize(ptr));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mu->_total_size += increment;
|
||||||
|
|
||||||
#ifdef TRACK_IN_INTERPRETER
|
#ifdef TRACK_IN_INTERPRETER
|
||||||
if (in_interpreter) {
|
if (in_interpreter) {
|
||||||
mu->_interpreter_size += increment;
|
mu->_interpreter_size += increment;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -384,26 +382,18 @@ MemoryUsage(const MemoryHook ©) : MemoryHook(copy) {
|
|||||||
PRC_DESC("Set this to true to enable full-force tracking of C++ allocations "
|
PRC_DESC("Set this to true to enable full-force tracking of C++ allocations "
|
||||||
"and recordkeeping by type. It's quite expensive."));
|
"and recordkeeping by type. It's quite expensive."));
|
||||||
|
|
||||||
#if defined(WIN32_VC) && defined(_DEBUG)
|
|
||||||
_count_memory_usage = ConfigVariableBool
|
|
||||||
("count-memory-usage", _track_memory_usage,
|
|
||||||
PRC_DESC("This is a much lighter-weight version of track-memory-usage, and it "
|
|
||||||
"only tracks the total memory allocation. However, it only exists in "
|
|
||||||
"certain build environments (in particular, only in an Opt1 or "
|
|
||||||
"Opt2 build on Windows."));
|
|
||||||
|
|
||||||
#else
|
|
||||||
_count_memory_usage = false;
|
_count_memory_usage = false;
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_MEMORY_NOWRAPPERS
|
#ifdef USE_MEMORY_NOWRAPPERS
|
||||||
#error Cannot compile MemoryUsage without malloc wrappers!
|
#error Cannot compile MemoryUsage without malloc wrappers!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WIN32_VC) && defined(_DEBUG)
|
#if defined(WIN32_VC) && defined(_DEBUG)
|
||||||
if (_count_memory_usage) {
|
// On a debug Windows build, we can set this malloc hook which
|
||||||
_CrtSetAllocHook(&win32_malloc_hook);
|
// allows tracking every malloc call, even from subordinate
|
||||||
}
|
// libraries.
|
||||||
|
_CrtSetAllocHook(&win32_malloc_hook);
|
||||||
|
_count_memory_usage = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_info_set_dirty = false;
|
_info_set_dirty = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user