UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FGenericPlatformMallocCrash Struct Referencefinal

#include <GenericPlatformMallocCrash.h>

+ Inheritance diagram for FGenericPlatformMallocCrash:

Public Types

enum  {
  LARGE_MEMORYPOOL_SIZE = 2 * 1024 * 1024 , REQUIRED_ALIGNMENT = 16 , NUM_POOLS = 14 , MAX_NUM_ALLOCS_IN_POOL = 2048 ,
  MEM_TAG = 0xfe , MEM_WIPETAG = 0xcd
}
 

Public Member Functions

 FGenericPlatformMallocCrash (FMalloc *MainMalloc)
 
virtual ~FGenericPlatformMallocCrash ()
 
void SetAsGMalloc ()
 
virtual voidMalloc (SIZE_T Size, uint32 Alignment) override
 
virtual voidRealloc (void *Ptr, SIZE_T NewSize, uint32 Alignment) override
 
virtual void Free (void *) override
 
virtual bool GetAllocationSize (void *Original, SIZE_T &SizeOut) override
 
virtual bool IsInternallyThreadSafe () const override
 
virtual bool ValidateHeap () override
 
virtual const TCHARGetDescriptiveName () override
 
CORE_API void PrintPoolsUsage ()
 
- 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 SIZE_T QuantizeSize (SIZE_T Count, uint32 Alignment)
 
virtual void Trim (bool bTrimThreadCaches)
 
virtual void SetupTLSCachesOnCurrentThread ()
 
virtual void MarkTLSCachesAsUsedOnCurrentThread ()
 
virtual void MarkTLSCachesAsUnusedOnCurrentThread ()
 
virtual void ClearAndDisableTLSCachesOnCurrentThread ()
 
virtual CORE_API void InitializeStatsMetadata ()
 
virtual CORE_API void UpdateStats ()
 
virtual CORE_API void GetAllocatorStats (FGenericMemoryStats &out_Stats)
 
virtual void DumpAllocatorStats (class FOutputDevice &Ar)
 
virtual void OnMallocInitialized ()
 
virtual void OnPreFork ()
 
virtual void OnPostFork ()
 
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 Member Functions

static CORE_API FGenericPlatformMallocCrashGet (FMalloc *MainMalloc=nullptr)
 
static bool IsActive ()
 

Protected Member Functions

bool CheckThreadForAllocation () const
 
bool CheckThreadForFree () const
 
bool IsPtrInLargePool (void *Ptr) const
 
bool IsPtrInSmallPool (void *Ptr) const
 
const FPoolDescGetPoolDesc (uint32 Index) const
 
uint32 CalculateSmallPoolTotalSize () const
 
uint32 CalculateBookkeepingPoolTotalSize () const
 
void InitializeSmallPools ()
 
FMallocCrashPoolChoosePoolForSize (uint32 AllocationSize) const
 
FMallocCrashPoolFindPoolForAlloc (void *Ptr) const
 
uint8AllocateFromBookkeeping (uint32 AllocationSize)
 
uint8AllocateFromSmallPool (uint32 AllocationSize)
 
uint64 GetAllocationSize (void *Original)
 
- 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)
 

Static Protected Member Functions

static uint32 SafePageSize ()
 

Protected Attributes

FCriticalSection InternalLock
 
int32 CrashedThreadId = 0
 
uint8LargeMemoryPool = nullptr
 
uint32 LargeMemoryPoolOffset = 0
 
uint8SmallMemoryPool = nullptr
 
uint32 SmallMemoryPoolOffset = 0
 
uint32 SmallMemoryPoolSize = 0
 
uint8BookkeepingPool = nullptr
 
uint32 BookkeepingPoolOffset = 0
 
uint32 BookkeepingPoolSize = 0
 
FMallocPreviousMalloc = nullptr
 

Friends

struct FPoolDesc
 
struct FMallocCrashPool
 

Additional Inherited Members

- Static Public Attributes inherited from FMalloc
static CORE_API TAtomic< uint64MaxSingleAlloc
 

Detailed Description

Simple pooled memory allocator that uses preallocated memory. Instance of this class replaces GMalloc after a crash, so we can use dynamic memory allocation even if the app crashes due to OOM.

Member Enumeration Documentation

◆ anonymous enum

Enumerator
LARGE_MEMORYPOOL_SIZE 
REQUIRED_ALIGNMENT 
NUM_POOLS 
MAX_NUM_ALLOCS_IN_POOL 
MEM_TAG 
MEM_WIPETAG 

Constructor & Destructor Documentation

◆ FGenericPlatformMallocCrash()

FGenericPlatformMallocCrash::FGenericPlatformMallocCrash ( FMalloc MainMalloc)

◆ ~FGenericPlatformMallocCrash()

FGenericPlatformMallocCrash::~FGenericPlatformMallocCrash ( )
virtual

Member Function Documentation

◆ AllocateFromBookkeeping()

uint8 * FGenericPlatformMallocCrash::AllocateFromBookkeeping ( uint32  AllocationSize)
protected

◆ AllocateFromSmallPool()

uint8 * FGenericPlatformMallocCrash::AllocateFromSmallPool ( uint32  AllocationSize)
protected

◆ CalculateBookkeepingPoolTotalSize()

uint32 FGenericPlatformMallocCrash::CalculateBookkeepingPoolTotalSize ( ) const
protected

◆ CalculateSmallPoolTotalSize()

uint32 FGenericPlatformMallocCrash::CalculateSmallPoolTotalSize ( ) const
protected

◆ CheckThreadForAllocation()

PRAGMA_DISABLE_UNREACHABLE_CODE_WARNINGS bool FGenericPlatformMallocCrash::CheckThreadForAllocation ( ) const
protected

Whether it is safe to call crash malloc's methods.

◆ CheckThreadForFree()

bool FGenericPlatformMallocCrash::CheckThreadForFree ( ) const
protected

◆ ChoosePoolForSize()

FMallocCrashPool * FGenericPlatformMallocCrash::ChoosePoolForSize ( uint32  AllocationSize) const
protected

◆ FindPoolForAlloc()

FMallocCrashPool * FGenericPlatformMallocCrash::FindPoolForAlloc ( void Ptr) const
protected

◆ Free()

void FGenericPlatformMallocCrash::Free ( void Original)
overridevirtual

Free

Implements FMalloc.

◆ Get()

FGenericPlatformMallocCrash & FGenericPlatformMallocCrash::Get ( FMalloc MainMalloc = nullptr)
static

Creates a new instance.

◆ GetAllocationSize() [1/2]

uint64 FGenericPlatformMallocCrash::GetAllocationSize ( void Original)
protected

◆ GetAllocationSize() [2/2]

bool FGenericPlatformMallocCrash::GetAllocationSize ( void Original,
SIZE_T SizeOut 
)
overridevirtual

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.

◆ GetDescriptiveName()

virtual const TCHAR * FGenericPlatformMallocCrash::GetDescriptiveName ( )
inlineoverridevirtual

Gets descriptive name for logging purposes.

Returns
pointer to human-readable malloc name

Reimplemented from FMalloc.

◆ GetPoolDesc()

const FPoolDesc & FGenericPlatformMallocCrash::GetPoolDesc ( uint32  Index) const
protected

◆ InitializeSmallPools()

void FGenericPlatformMallocCrash::InitializeSmallPools ( )
protected

◆ IsActive()

bool FGenericPlatformMallocCrash::IsActive ( )
static

◆ IsInternallyThreadSafe()

virtual bool FGenericPlatformMallocCrash::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.

◆ IsPtrInLargePool()

PRAGMA_RESTORE_UNREACHABLE_CODE_WARNINGS bool FGenericPlatformMallocCrash::IsPtrInLargePool ( void Ptr) const
protected

◆ IsPtrInSmallPool()

bool FGenericPlatformMallocCrash::IsPtrInSmallPool ( void Ptr) const
protected

◆ Malloc()

void * FGenericPlatformMallocCrash::Malloc ( SIZE_T  Count,
uint32  Alignment 
)
overridevirtual

Malloc

Implements FMalloc.

◆ PrintPoolsUsage()

void FGenericPlatformMallocCrash::PrintPoolsUsage ( )

◆ Realloc()

void * FGenericPlatformMallocCrash::Realloc ( void Original,
SIZE_T  Count,
uint32  Alignment 
)
overridevirtual

Realloc

Implements FMalloc.

◆ SafePageSize()

uint32 FGenericPlatformMallocCrash::SafePageSize ( )
staticprotected
Returns
page size, if page size is not initialized, returns 64k.

◆ SetAsGMalloc()

void FGenericPlatformMallocCrash::SetAsGMalloc ( )

Sets as GMalloc. This method locks to the thread that crashed. Any next calls to this method or GMalloc from other threads will dead-lock those threads, but this is ok, because we are shutting down. This also fixes a lot of potential issues of using dynamic allocation during crash dumping.

Warning
This is not super safe, may interfere with other allocations, ie. replacing vtable during running the code from the previous malloc will probably crash other threads.

◆ ValidateHeap()

virtual bool FGenericPlatformMallocCrash::ValidateHeap ( )
inlineoverridevirtual

Validates the allocator's heap

Reimplemented from FMalloc.

Friends And Related Symbol Documentation

◆ FMallocCrashPool

◆ FPoolDesc

Member Data Documentation

◆ BookkeepingPool

uint8* FGenericPlatformMallocCrash::BookkeepingPool = nullptr
protected

Preallocated memory pool for bookkeeping.

◆ BookkeepingPoolOffset

uint32 FGenericPlatformMallocCrash::BookkeepingPoolOffset = 0
protected

Current position in the bookkeeping pool.

◆ BookkeepingPoolSize

uint32 FGenericPlatformMallocCrash::BookkeepingPoolSize = 0
protected

◆ CrashedThreadId

int32 FGenericPlatformMallocCrash::CrashedThreadId = 0
protected

The id of the thread that crashed.

◆ InternalLock

FCriticalSection FGenericPlatformMallocCrash::InternalLock
protected

Used to lock crash malloc to one thread.

◆ LargeMemoryPool

uint8* FGenericPlatformMallocCrash::LargeMemoryPool = nullptr
protected

Preallocated memory pool for large allocations.

◆ LargeMemoryPoolOffset

uint32 FGenericPlatformMallocCrash::LargeMemoryPoolOffset = 0
protected

Current position in the large memory pool.

◆ PreviousMalloc

FMalloc* FGenericPlatformMallocCrash::PreviousMalloc = nullptr
protected

Previously used malloc.

◆ SmallMemoryPool

uint8* FGenericPlatformMallocCrash::SmallMemoryPool = nullptr
protected

Preallocated memory pool for small allocations.

◆ SmallMemoryPoolOffset

uint32 FGenericPlatformMallocCrash::SmallMemoryPoolOffset = 0
protected

Current position in the small memory pool.

◆ SmallMemoryPoolSize

uint32 FGenericPlatformMallocCrash::SmallMemoryPoolSize = 0
protected

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