FMalloc

The global memory allocator's interface.

Choose your operating system:

Windows

macOS

Linux

Inheritance Hierarchy

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/HAL/MemoryBase.h

Include

#include "HAL/MemoryBase.h"

Syntax

class FMalloc :
    public FUseSystemMallocForNew,
    public FExec

Remarks

The global memory allocator's interface.

Functions

Name Description

Public function Virtual

void

 

ClearAndDisableTLSCachesOnCurrentThread()

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

Public function Virtual

void

 

DumpAllocatorStats

(
    FOutputDevice& Ar
)

Dumps current allocator stats to the log.

Public function

void

 

Free

(
    void* Original
)

Free

Public function Virtual

bool

 

GetAllocationSize

(
    void* Original,
    SIZE_T& SizeOut
)

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

Public function Virtual

void

 

GetAllocatorStats

(
    FGenericMemoryStats& out_Stats
)

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

Public function Virtual

const TCHAR ...

 

GetDescriptiveName()

Gets descriptive name for logging purposes.

Public function Virtual

void

 

InitializeStatsMetadata()

Initializes stats metadata.

Public function Virtual Const

bool

 

IsInternallyThreadSafe()

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

Public function

void *

 

Malloc

(
    SIZE_T Count,
    uint32 Alignment
)

Malloc

Public function Virtual

SIZE_T

 

QuantizeSize

(
    SIZE_T Count,
    uint32 Alignment
)

For some allocators this will return the actual size that should be requested to eliminate internal fragmentation.

Public function

void *

 

Realloc

(
    void* Original,
    SIZE_T Count,
    uint32 Alignment
)

Realloc

Public function Virtual

void

 

SetupTLSCachesOnCurrentThread()

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

Public function Virtual

void

 

Trim

(
    bool bTrimThreadCaches
)

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

Public function Virtual

void *

 

TryMalloc

(
    SIZE_T Count,
    uint32 Alignment
)

TryMalloc - like Malloc(), but may return a nullptr result if the allocation request cannot be satisfied.

Public function Virtual

void *

 

TryRealloc

(
    void* Original,
    SIZE_T Count,
    uint32 Alignment
)

TryRealloc - like Realloc(), but may return a nullptr if the allocation request cannot be satisfied.

Public function Virtual

void

 

UpdateStats()

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

Public function Virtual

bool

 

ValidateHeap()

Validates the allocator's heap

Overridden from FExec

Name Description

Public function Virtual

bool

 

Exec

(
    UWorld* InWorld,
    const TCHAR* Cmd,
    FOutputDevice& Ar
)

Handles any commands passed in on the command line

Constants

Name

Description

MaxSingleAlloc

Limits the maximum single allocation, to this many bytes, for debugging