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

Function realloc

engine/dlib/src/dlib/memprofile.cpp:556–612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

554
555extern "C"
556DM_DLLEXPORT void *realloc(void* ptr, size_t size)
557{
558 // This simplifies the code below a bit
559 if (ptr == 0)
560 return malloc(size);
561
562 if (!reallocp)
563 {
564 CreateHooks();
565 }
566
567 size_t old_usable_size = 0;
568#if defined(__linux__)
569 old_usable_size = malloc_usable_size(ptr);
570#elif defined(__MACH__)
571 old_usable_size = malloc_size(ptr);
572#else
573#error "Unsupported platform"
574#endif
575
576 void* old_ptr = ptr;
577 ptr = reallocp(ptr, size);
578 if (ptr)
579 {
580 size_t usable_size = 0;
581#if defined(__linux__)
582 usable_size = malloc_usable_size(ptr);
583#elif defined(__MACH__)
584 usable_size = malloc_size(ptr);
585#else
586#error "Unsupported platform"
587#endif
588
589 dmMemProfile::DumpBacktrace('F', old_ptr, old_usable_size);
590 dmMemProfile::DumpBacktrace('M', ptr, usable_size);
591
592 if (dmMemProfile::g_ExtStats)
593 {
594 dmAtomicSub32(&dmMemProfile::g_ExtStats->m_TotalActive, (uint32_t) old_usable_size);
595
596 dmAtomicAdd32(&dmMemProfile::g_ExtStats->m_TotalAllocated, (uint32_t) usable_size);
597 dmAtomicAdd32(&dmMemProfile::g_ExtStats->m_TotalActive, (uint32_t) usable_size);
598 dmAtomicAdd32(&dmMemProfile::g_ExtStats->m_AllocationCount, 1U);
599
600 if (dmMemProfile::m_PropertyAddU32)
601 {
602 dmMemProfile::m_PropertyAddU32(dmMemProfile::g_ProfileAllocations, 1U);
603 dmMemProfile::m_PropertyAddU32(dmMemProfile::g_ProfileAmount, usable_size);
604 }
605 }
606 }
607 else
608 {
609 // Nothing happended
610 }
611 return ptr;
612}
613

Callers 15

ReloadModuleFunction · 0.85
strbuf_resizeFunction · 0.85
CRTReallocFunction · 0.85
increase_capacityMethod · 0.85
AllocateMethod · 0.85
UpdateReversHashStateMethod · 0.85
SetCapacityMethod · 0.85
scandirFunction · 0.85
TESTFunction · 0.85

Calls 5

mallocFunction · 0.85
CreateHooksFunction · 0.85
DumpBacktraceFunction · 0.85
dmAtomicSub32Function · 0.85
dmAtomicAdd32Function · 0.85

Tested by 6

TESTFunction · 0.68
StreamingPreloadCallbackFunction · 0.68
AddShaderFunction · 0.68
AddShaderResourceFunction · 0.68
AddShaderTypeFunction · 0.68
AddShaderTypeMemberFunction · 0.68