MCPcopy Create free account
hub / github.com/defold/defold / malloc

Function malloc

engine/dlib/src/dlib/memprofile.cpp:382–422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380
381extern "C"
382DM_DLLEXPORT void *malloc(size_t size)
383{
384 if (!mallocp)
385 {
386 CreateHooks();
387 }
388
389 void *ptr = mallocp(size);
390
391 if (ptr)
392 {
393 size_t usable_size = 0;
394#if defined(__linux__)
395 usable_size = malloc_usable_size(ptr);
396#elif defined(__MACH__)
397 usable_size = malloc_size(ptr);
398#else
399#error "Unsupported platform"
400#endif
401
402 dmMemProfile::DumpBacktrace('M', ptr, usable_size);
403
404 if (dmMemProfile::g_ExtStats)
405 {
406 dmAtomicAdd32(&dmMemProfile::g_ExtStats->m_TotalAllocated, (uint32_t) usable_size);
407 dmAtomicAdd32(&dmMemProfile::g_ExtStats->m_TotalActive, (uint32_t) usable_size);
408 dmAtomicAdd32(&dmMemProfile::g_ExtStats->m_AllocationCount, 1U);
409
410 if (dmMemProfile::m_PropertyAddU32)
411 {
412 dmMemProfile::m_PropertyAddU32(dmMemProfile::g_ProfileAllocations, 1U);
413 dmMemProfile::m_PropertyAddU32(dmMemProfile::g_ProfileAmount, usable_size);
414 }
415 }
416 }
417 else
418 {
419 dmMemProfile::DumpBacktrace('M', 0, 0);
420 }
421 return ptr;
422}
423
424#ifndef __MACH__
425extern "C"

Callers 15

InstallHandlerFunction · 0.85
CompScriptOnMessageFunction · 0.85
AcquireResourcesFunction · 0.85
ComponentTypeTest_CreateFunction · 0.85
ReadFileFunction · 0.85
cgltf_write_fileFunction · 0.85
AddModuleFunction · 0.85
InitializeFunction · 0.85
NewScriptWorldFunction · 0.85
HttpWriteHeadersFunction · 0.85
SendResponseFunction · 0.85

Calls 3

CreateHooksFunction · 0.85
DumpBacktraceFunction · 0.85
dmAtomicAdd32Function · 0.85

Tested by 15

ComponentTypeTest_CreateFunction · 0.68
TEST_FFunction · 0.68
TEST_FFunction · 0.68
ReadFileFunction · 0.68
TESTFunction · 0.68
GetMethod · 0.68
TEST_FFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
func2Function · 0.68
func1aFunction · 0.68