| 511 | |
| 512 | extern "C" |
| 513 | DM_DLLEXPORT void *calloc(size_t count, size_t size) |
| 514 | { |
| 515 | if (!callocp) |
| 516 | { |
| 517 | CreateHooks(); |
| 518 | } |
| 519 | |
| 520 | void *ptr = callocp(count, size); |
| 521 | |
| 522 | if (ptr) |
| 523 | { |
| 524 | size_t usable_size = 0; |
| 525 | #if defined(__linux__) |
| 526 | usable_size = malloc_usable_size(ptr); |
| 527 | #elif defined(__MACH__) |
| 528 | usable_size = malloc_size(ptr); |
| 529 | #else |
| 530 | #error "Unsupported platform" |
| 531 | #endif |
| 532 | |
| 533 | dmMemProfile::DumpBacktrace('M', ptr, usable_size); |
| 534 | |
| 535 | if (dmMemProfile::g_ExtStats) |
| 536 | { |
| 537 | dmAtomicAdd32(&dmMemProfile::g_ExtStats->m_TotalAllocated, (uint32_t) usable_size); |
| 538 | dmAtomicAdd32(&dmMemProfile::g_ExtStats->m_TotalActive, (uint32_t) usable_size); |
| 539 | dmAtomicAdd32(&dmMemProfile::g_ExtStats->m_AllocationCount, 1U); |
| 540 | |
| 541 | if (dmMemProfile::m_PropertyAddU32) |
| 542 | { |
| 543 | dmMemProfile::m_PropertyAddU32(dmMemProfile::g_ProfileAllocations, 1U); |
| 544 | dmMemProfile::m_PropertyAddU32(dmMemProfile::g_ProfileAmount, usable_size); |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | else |
| 549 | { |
| 550 | dmMemProfile::DumpBacktrace('M', 0, 0); |
| 551 | } |
| 552 | return ptr; |
| 553 | } |
| 554 | |
| 555 | extern "C" |
| 556 | DM_DLLEXPORT void *realloc(void* ptr, size_t size) |