UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FMallocCallstackHandler Class Referenceabstract

#include <MallocCallstackHandler.h>

+ Inheritance diagram for FMallocCallstackHandler:

Classes

struct  FCallStackInfo
 
struct  FCallStackMapKey
 

Public Member Functions

CORE_API FMallocCallstackHandler (FMalloc *InMalloc)
 
virtual CORE_API voidMalloc (SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT) override
 
virtual CORE_API voidRealloc (void *Original, SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT) override
 
virtual CORE_API void Free (void *Original) override
 
virtual SIZE_T QuantizeSize (SIZE_T Count, uint32 Alignment) override
 
virtual bool GetAllocationSize (void *Original, SIZE_T &SizeOut) override
 
virtual void Trim (bool bTrimThreadCaches) override
 
virtual void SetupTLSCachesOnCurrentThread () override
 
virtual void MarkTLSCachesAsUsedOnCurrentThread () override
 
virtual void MarkTLSCachesAsUnusedOnCurrentThread ()
 
virtual void ClearAndDisableTLSCachesOnCurrentThread () override
 
virtual void InitializeStatsMetadata () override
 
virtual void UpdateStats () override
 
virtual void GetAllocatorStats (FGenericMemoryStats &out_Stats) override
 
virtual void DumpAllocatorStats (class FOutputDevice &Ar) override
 
virtual bool IsInternallyThreadSafe () const override
 
virtual bool ValidateHeap () override
 
virtual const TCHARGetDescriptiveName () override
 
virtual void OnMallocInitialized () override
 
virtual void OnPreFork () override
 
virtual void OnPostFork () override
 
virtual void Init ()
 
void DumpStackTraceToLog (int32 StackIndex)
 
- Public Member Functions inherited from FMalloc
virtual CORE_API voidTryMalloc (SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)
 
virtual CORE_API voidTryRealloc (void *Original, SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)
 
virtual CORE_API voidMallocZeroed (SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)
 
virtual CORE_API voidTryMallocZeroed (SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)
 
virtual uint64 GetImmediatelyFreeableCachedMemorySize () const
 
virtual uint64 GetTotalFreeCachedMemorySize () const
 
- Public Member Functions inherited from FUseSystemMallocForNew
CORE_API voidoperator new (size_t Size)
 
CORE_API void operator delete (void *Ptr)
 
voidoperator new[] (size_t Size)
 
void operator delete[] (void *Ptr)
 
- Public Member Functions inherited from FExec
virtual CORE_API ~FExec ()
 
virtual CORE_API bool Exec (UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar)
 

Static Public Attributes

static constexpr SIZE_T MaxCallStackDepth = 64
 
static constexpr SIZE_T CallStackEntriesToSkipCount = 2
 
- Static Public Attributes inherited from FMalloc
static CORE_API TAtomic< uint64MaxSingleAlloc
 

Protected Member Functions

void IncDisabled ()
 
void DecDisabled ()
 
virtual bool IsDisabled ()
 
virtual CORE_API void TrackRealloc (void *OldPtr, void *NewPtr, uint32 NewSize, uint32 OldSize, int32 CallStackIndex)
 
virtual void TrackMalloc (void *Ptr, uint32 Size, int32 CallStackIndex)=0
 
virtual void TrackFree (void *Ptr, uint32 OldSize, int32 CallStackIndex)=0
 
virtual int32 GetCallStackIndex ()
 
- Protected Member Functions inherited from FExec
virtual bool Exec_Runtime (UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar)
 
virtual bool Exec_Dev (UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar)
 
virtual bool Exec_Editor (UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar)
 

Protected Attributes

FMallocUsedMalloc
 
bool Initialized
 
FCriticalSection CriticalSection
 
uint32 DisabledTLS
 
FRWLock RWLock
 
TMap< FCallStackMapKey, int32CallStackMapKeyToCallStackIndexMap
 
TArray< FCallStackInfoCallStackInfoArray
 

Friends

class FScopeDisableMallocCallstackHandler
 

Constructor & Destructor Documentation

◆ FMallocCallstackHandler()

FMallocCallstackHandler::FMallocCallstackHandler ( FMalloc InMalloc)

Member Function Documentation

◆ ClearAndDisableTLSCachesOnCurrentThread()

virtual void FMallocCallstackHandler::ClearAndDisableTLSCachesOnCurrentThread ( )
inlineoverridevirtual

Clears the TLS caches on the current thread and disables any future caching.

Reimplemented from FMalloc.

◆ DecDisabled()

void FMallocCallstackHandler::DecDisabled ( )
inlineprotected

◆ DumpAllocatorStats()

virtual void FMallocCallstackHandler::DumpAllocatorStats ( class FOutputDevice Ar)
inlineoverridevirtual

Dumps current allocator stats to the log.

Reimplemented from FMalloc.

◆ DumpStackTraceToLog()

FORCENOINLINE void FMallocCallstackHandler::DumpStackTraceToLog ( int32  StackIndex)

◆ Free()

void FMallocCallstackHandler::Free ( void Original)
overridevirtual

Free

Implements FMalloc.

◆ GetAllocationSize()

virtual bool FMallocCallstackHandler::GetAllocationSize ( void Original,
SIZE_T SizeOut 
)
inlineoverridevirtual

If possible determine the size of the memory allocated at the given address

Parameters
Original- Pointer to memory we are checking the size of
SizeOut- If possible, this value is set to the size of the passed in pointer
Returns
true if succeeded

Reimplemented from FMalloc.

◆ GetAllocatorStats()

virtual void FMallocCallstackHandler::GetAllocatorStats ( FGenericMemoryStats out_Stats)
inlineoverridevirtual

Writes allocator stats from the last update into the specified destination.

Reimplemented from FMalloc.

◆ GetCallStackIndex()

int32 FMallocCallstackHandler::GetCallStackIndex ( )
protectedvirtual

◆ GetDescriptiveName()

virtual const TCHAR * FMallocCallstackHandler::GetDescriptiveName ( )
inlineoverridevirtual

Gets descriptive name for logging purposes.

Returns
pointer to human-readable malloc name

Reimplemented from FMalloc.

◆ IncDisabled()

void FMallocCallstackHandler::IncDisabled ( )
inlineprotected

◆ Init()

void FMallocCallstackHandler::Init ( )
virtual

◆ InitializeStatsMetadata()

virtual void FMallocCallstackHandler::InitializeStatsMetadata ( )
inlineoverridevirtual

Initializes stats metadata. We need to do this as soon as possible, but cannot be done in the constructor due to the FName::StaticInit

Reimplemented from FMalloc.

◆ IsDisabled()

virtual bool FMallocCallstackHandler::IsDisabled ( )
inlineprotectedvirtual

Reimplemented in FMallocFrameProfiler.

◆ IsInternallyThreadSafe()

virtual bool FMallocCallstackHandler::IsInternallyThreadSafe ( ) const
inlineoverridevirtual

Returns if the allocator is guaranteed to be thread-safe and therefore doesn't need a unnecessary thread-safety wrapper around it.

Reimplemented from FMalloc.

◆ Malloc()

void * FMallocCallstackHandler::Malloc ( SIZE_T  Count,
uint32  Alignment = DEFAULT_ALIGNMENT 
)
overridevirtual

Malloc

Implements FMalloc.

◆ MarkTLSCachesAsUnusedOnCurrentThread()

virtual void FMallocCallstackHandler::MarkTLSCachesAsUnusedOnCurrentThread ( )
inlinevirtual

Mark TLS caches for current thread as unused. Typically before going to sleep. These are the threads that we can trim without waking them up.

Reimplemented from FMalloc.

◆ MarkTLSCachesAsUsedOnCurrentThread()

virtual void FMallocCallstackHandler::MarkTLSCachesAsUsedOnCurrentThread ( )
inlineoverridevirtual

Mark TLS caches for the current thread as used. Thread has woken up to do some processing and needs its TLS caches back.

Reimplemented from FMalloc.

◆ OnMallocInitialized()

virtual void FMallocCallstackHandler::OnMallocInitialized ( )
inlineoverridevirtual

Notifies the malloc implementation that initialization of all allocators in GMalloc is complete, so it's safe to initialize any extra features that require "regular" allocations

Reimplemented from FMalloc.

◆ OnPostFork()

virtual void FMallocCallstackHandler::OnPostFork ( )
inlineoverridevirtual

Notifies the malloc implementation that the process has forked so we can try and avoid dirtying pre-fork pages.

Reimplemented from FMalloc.

◆ OnPreFork()

virtual void FMallocCallstackHandler::OnPreFork ( )
inlineoverridevirtual

Notifies the malloc implementation that the process is about to fork. May be used to trim caches etc.

Reimplemented from FMalloc.

◆ QuantizeSize()

virtual SIZE_T FMallocCallstackHandler::QuantizeSize ( SIZE_T  Count,
uint32  Alignment 
)
inlineoverridevirtual

For some allocators this will return the actual size that should be requested to eliminate internal fragmentation. The return value will always be >= Count. This can be used to grow and shrink containers to optimal sizes. This call is always fast and thread safe with no locking.

Reimplemented from FMalloc.

◆ Realloc()

void * FMallocCallstackHandler::Realloc ( void Original,
SIZE_T  Count,
uint32  Alignment = DEFAULT_ALIGNMENT 
)
overridevirtual

Realloc

Implements FMalloc.

◆ SetupTLSCachesOnCurrentThread()

virtual void FMallocCallstackHandler::SetupTLSCachesOnCurrentThread ( )
inlineoverridevirtual

Set up TLS caches on the current thread. These are the threads that we can trim.

Reimplemented from FMalloc.

◆ TrackFree()

virtual void FMallocCallstackHandler::TrackFree ( void Ptr,
uint32  OldSize,
int32  CallStackIndex 
)
protectedpure virtual

◆ TrackMalloc()

virtual void FMallocCallstackHandler::TrackMalloc ( void Ptr,
uint32  Size,
int32  CallStackIndex 
)
protectedpure virtual

◆ TrackRealloc()

void FMallocCallstackHandler::TrackRealloc ( void OldPtr,
void NewPtr,
uint32  NewSize,
uint32  OldSize,
int32  CallStackIndex 
)
protectedvirtual

Reimplemented in FMallocFrameProfiler.

◆ Trim()

virtual void FMallocCallstackHandler::Trim ( bool  bTrimThreadCaches)
inlineoverridevirtual

Releases as much memory as possible. Must be called from the main thread.

Reimplemented from FMalloc.

◆ UpdateStats()

virtual void FMallocCallstackHandler::UpdateStats ( )
inlineoverridevirtual

Called once per frame, gathers and sets all memory allocator statistics into the corresponding stats. MUST BE THREAD SAFE.

Reimplemented from FMalloc.

Reimplemented in FMallocFrameProfiler.

◆ ValidateHeap()

virtual bool FMallocCallstackHandler::ValidateHeap ( )
inlineoverridevirtual

Validates the allocator's heap

Reimplemented from FMalloc.

Friends And Related Symbol Documentation

◆ FScopeDisableMallocCallstackHandler

Member Data Documentation

◆ CallStackEntriesToSkipCount

constexpr SIZE_T FMallocCallstackHandler::CallStackEntriesToSkipCount = 2
inlinestaticconstexpr

◆ CallStackInfoArray

TArray<FCallStackInfo> FMallocCallstackHandler::CallStackInfoArray
protected

◆ CallStackMapKeyToCallStackIndexMap

TMap<FCallStackMapKey, int32> FMallocCallstackHandler::CallStackMapKeyToCallStackIndexMap
protected

◆ CriticalSection

FCriticalSection FMallocCallstackHandler::CriticalSection
protected

◆ DisabledTLS

uint32 FMallocCallstackHandler::DisabledTLS
protected

◆ Initialized

bool FMallocCallstackHandler::Initialized
protected

◆ MaxCallStackDepth

constexpr SIZE_T FMallocCallstackHandler::MaxCallStackDepth = 64
inlinestaticconstexpr

◆ RWLock

FRWLock FMallocCallstackHandler::RWLock
protected

◆ UsedMalloc

FMalloc* FMallocCallstackHandler::UsedMalloc
protected

Malloc we're based on, aka using under the hood


The documentation for this class was generated from the following files: