UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FGenericPlatformMemory Struct Reference

#include <GenericPlatformMemory.h>

+ Inheritance diagram for FGenericPlatformMemory:

Classes

class  FBasicVirtualMemoryBlock
 
struct  FSharedMemoryRegion
 

Public Types

enum  EMemoryCounterRegion {
  MCR_Invalid , MCR_Physical , MCR_GPU , MCR_GPUSystem ,
  MCR_TexturePool , MCR_StreamingPool , MCR_UsedStreamingPool , MCR_GPUDefragPool ,
  MCR_PhysicalLLM , MCR_MAX
}
 
enum  EMemoryAllocatorToUse {
  Ansi , Stomp , TBB , Jemalloc ,
  Binned , Binned2 , Binned3 , Platform ,
  Mimalloc , Libpas
}
 
enum  ESharedMemoryAccess { Read = (1 << 1) , Write = (1 << 2) }
 

Static Public Member Functions

static CORE_API void Init ()
 
static CORE_API void OnOutOfMemory (uint64 Size, uint32 Alignment)
 
static CORE_API void SetupMemoryPools ()
 
static uint32 GetBackMemoryPoolSize ()
 
static CORE_API FMallocBaseAllocator ()
 
static CORE_API FPlatformMemoryStats GetStats ()
 
static CORE_API FPlatformMemoryStats GetStatsRaw ()
 
static CORE_API uint64 GetMemoryUsedFast ()
 
static CORE_API void GetStatsForMallocProfiler (FGenericMemoryStats &out_Stats)
 
static CORE_API const FPlatformMemoryConstantsGetConstants ()
 
static CORE_API uint32 GetPhysicalGBRam ()
 
static CORE_API bool PageProtect (void *const Ptr, const SIZE_T Size, const bool bCanRead, const bool bCanWrite)
 
static CORE_API voidBinnedAllocFromOS (SIZE_T Size)
 
static CORE_API void BinnedFreeToOS (void *Ptr, SIZE_T Size)
 
static void MiMallocInit ()
 
static void NanoMallocInit ()
 
static bool PtrIsOSMalloc (void *Ptr)
 
static bool IsNanoMallocAvailable ()
 
static bool PtrIsFromNanoMalloc (void *Ptr)
 
static bool BinnedPlatformHasMemoryPoolForThisSize (SIZE_T Size)
 
static CORE_API void DumpStats (FOutputDevice &Ar)
 
static CORE_API void DumpPlatformAndAllocatorStats (FOutputDevice &Ar)
 
static CORE_API EPlatformMemorySizeBucket GetMemorySizeBucket ()
 

Static Public Attributes

static CORE_API bool bIsOOM = false
 
static CORE_API uint64 OOMAllocationSize = 0
 
static CORE_API uint32 OOMAllocationAlignment = 0
 
static CORE_API voidBackupOOMMemoryPool = nullptr
 
static CORE_API uint32 BackupOOMMemoryPoolSize
 
static CORE_API EMemoryAllocatorToUse AllocatorToUse = Platform
 

Memory functions

struct FGenericStatsUpdater
 
static CORE_API uint64 ProgramSize = 0
 
static UE_FORCEINLINE_HINT voidMemmove (void *Dest, const void *Src, SIZE_T Count)
 
static UE_FORCEINLINE_HINT int32 Memcmp (const void *Buf1, const void *Buf2, SIZE_T Count)
 
static UE_FORCEINLINE_HINT voidMemset (void *Dest, uint8 Char, SIZE_T Count)
 
static UE_FORCEINLINE_HINT voidMemzero (void *Dest, SIZE_T Count)
 
static UE_FORCEINLINE_HINT voidMemcpy (void *Dest, const void *Src, SIZE_T Count)
 
static UE_FORCEINLINE_HINT voidBigBlockMemcpy (void *Dest, const void *Src, SIZE_T Count)
 
static UE_FORCEINLINE_HINT voidStreamingMemcpy (void *Dest, const void *Src, SIZE_T Count)
 
static voidParallelMemcpy (void *Dest, const void *Src, SIZE_T Count, EMemcpyCachePolicy Policy=EMemcpyCachePolicy::StoreCached)
 
static void Memswap (void *Ptr1, void *Ptr2, SIZE_T Size)
 
template<typename T >
staticReadUnaligned (const void *Ptr)
 
template<typename T >
static UE_FORCEINLINE_HINT void WriteUnaligned (void *Ptr, const T &InValue)
 
static CORE_API FSharedMemoryRegionMapNamedSharedMemoryRegion (const FString &Name, bool bCreate, uint32 AccessMode, SIZE_T Size)
 
static CORE_API bool UnmapNamedSharedMemoryRegion (FSharedMemoryRegion *MemoryRegion)
 
static UE_FORCEINLINE_HINT bool SupportsFastVRAMMemory ()
 
static CORE_API bool IsExtraDevelopmentMemoryAvailable ()
 
static CORE_API uint64 GetExtraDevelopmentMemorySize ()
 
static uint64 GetProgramSize ()
 
static void SetProgramSize (uint64 InProgramSize)
 
static CORE_API bool GetLLMAllocFunctions (void *(*&OutAllocFunction)(size_t), void(*&OutFreeFunction)(void *, size_t), int32 &OutAlignment)
 
static UE_FORCEINLINE_HINT void OnLowLevelMemory_Alloc (void const *Pointer, uint64 Size, uint64 Tag)
 
static UE_FORCEINLINE_HINT void OnLowLevelMemory_Free (void const *Pointer, uint64 Size, uint64 Tag)
 
static void RegisterCustomLLMTags ()
 
static void UpdateCustomLLMTags ()
 
static bool TracksLLMAllocations ()
 
static bool HasForkPageProtectorEnabled ()
 
static bool GetForkedPageAllocationInfo (TArray< FForkedPageAllocation > &OutPageAllocationInfos)
 
static CORE_API FString PrettyMemory (uint64 Memory)
 
static UE_FORCEINLINE_HINT bool CanOverallocateVirtualMemory ()
 
static CORE_API void InternalUpdateStats (const FPlatformMemoryStats &MemoryStats)
 

Detailed Description

Generic implementation for most platforms, these tend to be unused and unimplemented.

Member Enumeration Documentation

◆ EMemoryAllocatorToUse

Which allocator is being used

Enumerator
Ansi 
Stomp 
TBB 
Jemalloc 
Binned 
Binned2 
Binned3 
Platform 
Mimalloc 
Libpas 

◆ EMemoryCounterRegion

Various memory regions that can be used with memory stats. The exact meaning of the enums are relatively platform-dependent, although the general ones (Physical, GPU) are straightforward. A platform can add more of these, and it won't affect other platforms, other than a minuscule amount of memory for the StatManager to track the max available memory for each region (uses an array FPlatformMemory::MCR_MAX big)

Enumerator
MCR_Invalid 
MCR_Physical 
MCR_GPU 
MCR_GPUSystem 
MCR_TexturePool 
MCR_StreamingPool 
MCR_UsedStreamingPool 
MCR_GPUDefragPool 
MCR_PhysicalLLM 
MCR_MAX 

◆ ESharedMemoryAccess

Flags used for shared memory creation/open

Enumerator
Read 
Write 

Member Function Documentation

◆ BaseAllocator()

FMalloc * FGenericPlatformMemory::BaseAllocator ( )
static
Returns
the default allocator.

◆ BigBlockMemcpy()

static UE_FORCEINLINE_HINT void * FGenericPlatformMemory::BigBlockMemcpy ( void Dest,
const void Src,
SIZE_T  Count 
)
inlinestatic

Memcpy optimized for big blocks.

◆ BinnedAllocFromOS()

static CORE_API void * FGenericPlatformMemory::BinnedAllocFromOS ( SIZE_T  Size)
static

Allocates pages from the OS.

Parameters
SizeSize to allocate, not necessarily aligned
Returns
OS allocated pointer for use by binned allocator

◆ BinnedFreeToOS()

static CORE_API void FGenericPlatformMemory::BinnedFreeToOS ( void Ptr,
SIZE_T  Size 
)
static

Returns pages allocated by BinnedAllocFromOS to the OS.

Parameters
Apointer previously returned from BinnedAllocFromOS
Sizesize of the allocation previously passed to BinnedAllocFromOS

◆ BinnedPlatformHasMemoryPoolForThisSize()

static bool FGenericPlatformMemory::BinnedPlatformHasMemoryPoolForThisSize ( SIZE_T  Size)
inlinestatic

Some platforms may pool allocations of this size to reduce OS calls. This function serves as a hint for BinnedMalloc's CachedOSPageAllocator so it does not cache these allocations additionally

◆ CanOverallocateVirtualMemory()

static UE_FORCEINLINE_HINT bool FGenericPlatformMemory::CanOverallocateVirtualMemory ( )
inlinestatic

Return true if the platform can allocate a lot more virtual memory than physical memory It's true for most platforms, but iOS needs a special entitlement and Linux a kernel config for this

◆ DumpPlatformAndAllocatorStats()

void FGenericPlatformMemory::DumpPlatformAndAllocatorStats ( FOutputDevice Ar)
static

Dumps basic platform memory statistics and allocator specific statistics into the specified output device.

◆ DumpStats()

void FGenericPlatformMemory::DumpStats ( FOutputDevice Ar)
static

Dumps basic platform memory statistics into the specified output device.

◆ GetBackMemoryPoolSize()

static uint32 FGenericPlatformMemory::GetBackMemoryPoolSize ( )
inlinestatic
Returns
how much memory the platform should pre-allocate for crash handling (this will be allocated ahead of time, and freed when system runs out of memory).

◆ GetConstants()

const FPlatformMemoryConstants & FGenericPlatformMemory::GetConstants ( )
static
Returns
platform specific memory constants.

◆ GetExtraDevelopmentMemorySize()

uint64 FGenericPlatformMemory::GetExtraDevelopmentMemorySize ( )
static

Returns >0 if debug memory has been assigned to the title for general use. Only applies to platforms with fixed memory and no paging.

◆ GetForkedPageAllocationInfo()

static bool FGenericPlatformMemory::GetForkedPageAllocationInfo ( TArray< FForkedPageAllocation > &  OutPageAllocationInfos)
inlinestatic

Return the page allocations from the operating system (/proc/self/smaps). This only means something on platforms that can fork and have Copy On Write behavior.

◆ GetLLMAllocFunctions()

bool FGenericPlatformMemory::GetLLMAllocFunctions ( void *(*&)(size_t OutAllocFunction,
void(*&)(void *, size_t OutFreeFunction,
int32 OutAlignment 
)
static

This function sets AllocFunction and FreeFunction and returns true, or just returns false. These functions are the platform dependant low low low level functions that LLM uses to allocate memory.

◆ GetMemorySizeBucket()

EPlatformMemorySizeBucket FGenericPlatformMemory::GetMemorySizeBucket ( )
static

Return which "high level", per platform, memory bucket we are in

◆ GetMemoryUsedFast()

uint64 FGenericPlatformMemory::GetMemoryUsedFast ( )
static
Returns
memory used for platforms that can do it quickly (without affecting stat unit much)

◆ GetPhysicalGBRam()

uint32 FGenericPlatformMemory::GetPhysicalGBRam ( )
static
Returns
approximate physical RAM in GB.

◆ GetProgramSize()

static uint64 FGenericPlatformMemory::GetProgramSize ( )
inlinestatic

Returns initial program size or 0 if the platform doesn't track initial program size

◆ GetStats()

FPlatformMemoryStats FGenericPlatformMemory::GetStats ( )
static
Returns
platform specific current memory statistics. Note: On some platforms, unused allocator cached memory is taken into account in AvailablePhysical.

◆ GetStatsForMallocProfiler()

void FGenericPlatformMemory::GetStatsForMallocProfiler ( FGenericMemoryStats out_Stats)
static

Writes all platform specific current memory statistics in the format usable by the malloc profiler.

◆ GetStatsRaw()

FPlatformMemoryStats FGenericPlatformMemory::GetStatsRaw ( )
static
Returns
platform specific raw stats.

◆ HasForkPageProtectorEnabled()

static bool FGenericPlatformMemory::HasForkPageProtectorEnabled ( )
inlinestatic

Returns true if Protecting the parent processes pages has been enabled Only supported on platforms that support forking

◆ Init()

void FGenericPlatformMemory::Init ( )
static

Initializes platform memory specific constants.

◆ InternalUpdateStats()

void FGenericPlatformMemory::InternalUpdateStats ( const FPlatformMemoryStats MemoryStats)
staticprotected

Updates platform specific stats. This method is called through FGenericStatsUpdater from the task graph thread.

◆ IsExtraDevelopmentMemoryAvailable()

bool FGenericPlatformMemory::IsExtraDevelopmentMemoryAvailable ( )
static

Returns true if debug memory has been assigned to the title for general use. Only applies to platforms with fixed memory and no paging.

◆ IsNanoMallocAvailable()

static bool FGenericPlatformMemory::IsNanoMallocAvailable ( )
inlinestatic

Nano Malloc is Apple's tiny block allocator. Does the Nano malloc zone exist?

Returns
True if Nano malloc is enabled and available.

◆ MapNamedSharedMemoryRegion()

FGenericPlatformMemory::FSharedMemoryRegion * FGenericPlatformMemory::MapNamedSharedMemoryRegion ( const FString &  Name,
bool  bCreate,
uint32  AccessMode,
SIZE_T  Size 
)
static

Maps a named shared memory region into process address space (creates or opens it)

Parameters
Nameunique name of the shared memory region (should not contain [back]slashes to remain cross-platform).
bCreatewhether we're creating it or just opening existing (created by some other process).
AccessModemode which we will be accessing it (use values from ESharedMemoryAccess)
Sizesize of the buffer (should be >0. Also, the real size is subject to platform limitations and may be increased to match page size)
Returns
pointer to FSharedMemoryRegion (or its descendants) if successful, NULL if not.

◆ Memcmp()

static UE_FORCEINLINE_HINT int32 FGenericPlatformMemory::Memcmp ( const void Buf1,
const void Buf2,
SIZE_T  Count 
)
inlinestatic

◆ Memcpy()

static UE_FORCEINLINE_HINT void * FGenericPlatformMemory::Memcpy ( void Dest,
const void Src,
SIZE_T  Count 
)
inlinestatic

◆ Memmove()

static UE_FORCEINLINE_HINT void * FGenericPlatformMemory::Memmove ( void Dest,
const void Src,
SIZE_T  Count 
)
inlinestatic

Copies count bytes of characters from Src to Dest. If some regions of the source area and the destination overlap, memmove ensures that the original source bytes in the overlapping region are copied before being overwritten. NOTE: make sure that the destination buffer is the same size or larger than the source buffer!

◆ Memset()

static UE_FORCEINLINE_HINT void * FGenericPlatformMemory::Memset ( void Dest,
uint8  Char,
SIZE_T  Count 
)
inlinestatic

◆ Memswap()

static void FGenericPlatformMemory::Memswap ( void Ptr1,
void Ptr2,
SIZE_T  Size 
)
inlinestatic

◆ Memzero()

static UE_FORCEINLINE_HINT void * FGenericPlatformMemory::Memzero ( void Dest,
SIZE_T  Count 
)
inlinestatic

◆ MiMallocInit()

static void FGenericPlatformMemory::MiMallocInit ( )
inlinestatic

Performs initial setup for MiMalloc. This is a noop on platforms that do not support MiMalloc, or when MIMALLOC_ENABLED is not defined.

◆ NanoMallocInit()

static void FGenericPlatformMemory::NanoMallocInit ( )
inlinestatic

Performs initial setup for Nano malloc. This is a noop on non-apple platforms

◆ OnLowLevelMemory_Alloc()

static UE_FORCEINLINE_HINT void FGenericPlatformMemory::OnLowLevelMemory_Alloc ( void const *  Pointer,
uint64  Size,
uint64  Tag 
)
inlinestatic

Called for all default tracker LLM allocations and frees, when LLM is enabled. Provides a single alloc/free hook that platforms can implement to support platform specific memory analysis tools.

◆ OnLowLevelMemory_Free()

static UE_FORCEINLINE_HINT void FGenericPlatformMemory::OnLowLevelMemory_Free ( void const *  Pointer,
uint64  Size,
uint64  Tag 
)
inlinestatic

◆ OnOutOfMemory()

void FGenericPlatformMemory::OnOutOfMemory ( uint64  Size,
uint32  Alignment 
)
static

◆ PageProtect()

bool FGenericPlatformMemory::PageProtect ( void *const  Ptr,
const SIZE_T  Size,
const bool  bCanRead,
const bool  bCanWrite 
)
static

Changes the protection on a region of committed pages in the virtual address space.

Parameters
PtrAddress to the starting page of the region of pages whose access protection attributes are to be changed.
SizeThe size of the region whose access protection attributes are to be changed, in bytes.
bCanReadCan the memory be read.
bCanWriteCan the memory be written to.
Returns
True if the specified pages' protection mode was changed.

◆ ParallelMemcpy()

static void * FGenericPlatformMemory::ParallelMemcpy ( void Dest,
const void Src,
SIZE_T  Count,
EMemcpyCachePolicy  Policy = EMemcpyCachePolicy::StoreCached 
)
inlinestatic

On some platforms memcpy can be distributed over multiple threads for throughput.

◆ PrettyMemory()

FString FGenericPlatformMemory::PrettyMemory ( uint64  Memory)
static

Returns a pretty-string for an amount of memory given in bytes.

Parameters
Memoryamount in bytes
Returns
Memory in a pretty formatted string

◆ PtrIsFromNanoMalloc()

static bool FGenericPlatformMemory::PtrIsFromNanoMalloc ( void Ptr)
inlinestatic

Was this pointer allocated by in the Nano Malloc Zone? Currently only Apple platforms implement this to detect small block allocations.

Parameters
Thepointer to query
Returns
True if this pointer is in the Nano Malloc Region

◆ PtrIsOSMalloc()

static bool FGenericPlatformMemory::PtrIsOSMalloc ( void Ptr)
inlinestatic

Was this pointer allocated by the OS malloc? Currently only Apple platforms implement this to detect small block allocations.

Parameters
Thepointer to query
Returns
True if this pointer was allocated by the OS.

◆ ReadUnaligned()

template<typename T >
static T FGenericPlatformMemory::ReadUnaligned ( const void Ptr)
inlinestatic

Loads a simple POD type from unaligned memory.

Parameters
Ptrunaligned memory of at least size sizeof(T)
Returns
Value at Ptr

◆ RegisterCustomLLMTags()

static void FGenericPlatformMemory::RegisterCustomLLMTags ( )
inlinestatic

Called once at LLM initialization time to let the platform add any custom tags

◆ SetProgramSize()

static void FGenericPlatformMemory::SetProgramSize ( uint64  InProgramSize)
inlinestatic

Sets the initial program size

◆ SetupMemoryPools()

void FGenericPlatformMemory::SetupMemoryPools ( )
static

Initializes the memory pools, should be called by the init function.

◆ StreamingMemcpy()

static UE_FORCEINLINE_HINT void * FGenericPlatformMemory::StreamingMemcpy ( void Dest,
const void Src,
SIZE_T  Count 
)
inlinestatic

On some platforms memcpy optimized for big blocks that avoid L2 cache pollution are available

◆ SupportsFastVRAMMemory()

static UE_FORCEINLINE_HINT bool FGenericPlatformMemory::SupportsFastVRAMMemory ( )
inlinestatic

Gets whether this platform supports Fast VRAM memory Ie, whether TexCreate_FastVRAM flags actually mean something or not

Returns
bool true if supported, false if not

◆ TracksLLMAllocations()

static bool FGenericPlatformMemory::TracksLLMAllocations ( )
inlinestatic

Indicates whether LLM allocations are already accounted for with tracking and in GetStats. Returns true if LLM allocations come from a memory pool separate from the main engine's memory or are already tagged with tracking by the platform memory system. Returns false if LLM uses the regular memory shared with the engine and allocations are not tracked.

See also
GetLLMAllocFunctions

◆ UnmapNamedSharedMemoryRegion()

bool FGenericPlatformMemory::UnmapNamedSharedMemoryRegion ( FSharedMemoryRegion MemoryRegion)
static

Unmaps a name shared memory region

Parameters
MemoryRegionan object that encapsulates a shared memory region (will be destroyed even if function fails!)
Returns
true if successful

◆ UpdateCustomLLMTags()

static void FGenericPlatformMemory::UpdateCustomLLMTags ( )
inlinestatic

Called once per frame when LLM is collating the data for the current frame. Can be used to set platform-specific calculated tag data via SetTagAmountForTracker

◆ WriteUnaligned()

template<typename T >
static UE_FORCEINLINE_HINT void FGenericPlatformMemory::WriteUnaligned ( void Ptr,
const T &  InValue 
)
inlinestatic

Stores a simple POD type to unaligned memory.

Parameters
Ptrunaligned memory of at least size sizeof(T)
Valuevalue to write at Ptr

Friends And Related Symbol Documentation

◆ FGenericStatsUpdater

Member Data Documentation

◆ AllocatorToUse

FGenericPlatformMemory::EMemoryAllocatorToUse FGenericPlatformMemory::AllocatorToUse = Platform
static

Current allocator

◆ BackupOOMMemoryPool

void * FGenericPlatformMemory::BackupOOMMemoryPool = nullptr
static

Preallocated buffer to delete on out of memory. Used by OOM handling and crash reporting.

◆ BackupOOMMemoryPoolSize

CORE_API uint32 FGenericPlatformMemory::BackupOOMMemoryPoolSize
static

Size of BackupOOMMemoryPool in bytes.

◆ bIsOOM

bool FGenericPlatformMemory::bIsOOM = false
static

Set to true if we encounters out of memory.

◆ OOMAllocationAlignment

uint32 FGenericPlatformMemory::OOMAllocationAlignment = 0
static

Set to alignment of allocation that triggered out of memory, zero otherwise.

◆ OOMAllocationSize

uint64 FGenericPlatformMemory::OOMAllocationSize = 0
static

Set to size of allocation that triggered out of memory, zero otherwise.

◆ ProgramSize

uint64 FGenericPlatformMemory::ProgramSize = 0
staticprotected

Program memory allocation in bytes.


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