Navigation
API > API/Runtime > API/Runtime/Core
Optimized virtual memory allocator.
MallocBinned3 supports two types of allocations - large and small pool allocation:
For small pool allocation MallocBinned3 reserves contiguous range of virtual memory (a Pool) for each allocation size (a Bin). These Pools can be adjacent to each other in memory if BINNED3_USE_SEPARATE_VM_PER_POOL is set to 0. By default each Pool reserves 1 GB of address space, unless USE_512MB_MAX_MEMORY_PER_BLOCK_SIZE is defined to 1. Each Pool commits and decommits reserved memory in Blocks. Each Block is equal to at least one memory page in it's size. A Block contains N Bins in a way to minimize the tail memory waste. For example 16 bytes bins fit inside 4KB memory page without any waste; i.e. one Block for 16 byte Bins contains 256 bins. However 736 bytes Bin uses two 4KB pages in it's Block to minimize memory waste. Each Pool manages it's Blocks allocation via a Bit Tree (BlocksAllocatedBits\BlocksExhaustedBits members). And every Block manages it's Bins via a number of additional data structures - FPoolInfoSmall and FFreeBlock. FFreeBlock is an in-place header for the Block that's stored at the end of each block and contains info on number of free Bins and index of the next free Block if any Memory is allocated top down in a Block
For large allocations we go directly to OS, unless UE_MB3_USE_CACHED_PAGE_ALLOCATOR_FOR_LARGE_ALLOCS is defined to 1 Each allocation is handled via FPlatformVirtualMemoryBlock and information about it is stored in FPoolInfoFPoolInfo stores the original allocation size and how much memory was committed by the OS in case we need to realloc that allocation and there's enough tail waste to do that in place All FPoolInfo are stored in the PoolHashBucket and HashBucketFreeList
| Name | FMallocBinned3 |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/HAL/MallocBinned3.h |
| Include Path | #include "HAL/MallocBinned3.h" |
Syntax
class FMallocBinned3 : public TMallocBinnedCommon< FMallocBinned3, - 28672)/4096), >
Inheritance Hierarchy
- FExec → FMalloc → FMallocBinnedCommonBase → TMallocBinnedCommon → FMallocBinned3
- FUseSystemMallocForNew → FMalloc → FMallocBinnedCommonBase → TMallocBinnedCommon → FMallocBinned3
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FMallocBinned3
(
const FPlatformMemory::FPlatformVirtualMemoryBlock* ExternalMemoryBlock |
HAL/MallocBinned3.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual ~FMallocBinned3() |
HAL/MallocBinned3.h |
Structs
| Name | Remarks |
|---|---|
| FPoolInfo | |
| FPoolInfoSmall | |
| FPoolTable | Pool table. |
| Private |
Constants
| Name | Type | Remarks | Include Path | |
|---|---|---|---|---|
| Binned3BaseVMPtr | uint8 * | HAL/MallocBinned3.h | ||
| MallocBinned3 | FMallocBinned3 * | HAL/MallocBinned3.h | ||
| MemSizeToPoolIndex | uint8 | Mapping of sizes to small table indices. | HAL/MallocBinned3.h | |
| SmallBinSizesShifted | uint16 | +1 enables PoolIndexToBinSize(~0u / -1) dummy access that helps avoid PoolIndex == 0 branching in Realloc(), see ((!PoolIndex) | (NewSize > PoolIndexToBinSize(static_cast |
HAL/MallocBinned3.h |
Variables
Public
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Binned3BaseVMBlock | FPlatformMemory::FPlatformVirtualMemoryBlock | HAL/MallocBinned3.h | ||
| SmallPoolTables | FPoolTable | Pool tables for different pool sizes. | HAL/MallocBinned3.h |
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| SmallPoolInfosPerPlatformPage | uint32 | HAL/MallocBinned3.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
void Commit
(
uint32 InPoolIndex, |
HAL/MallocBinned3.h | ||
void Decommit
(
uint32 InPoolIndex, |
HAL/MallocBinned3.h | ||
void FlushCurrentThreadCacheInternal
(
bool bNewEpochOnly |
HAL/MallocBinned3.h | ||
void FreeBundles
(
FBundleNode* Bundles, |
HAL/MallocBinned3.h | ||
void FreeExternal
(
void* Ptr, |
HAL/MallocBinned3.h | ||
bool GetSmallAllocationSize
(
void* Ptr, |
HAL/MallocBinned3.h | ||
uint32 PoolIndexToBinSize
(
uint32 PoolIndex |
HAL/MallocBinned3.h |
Overridden from FMalloc
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void DumpAllocatorStats
(
FOutputDevice& Ar |
Dumps current allocator stats to the log. | HAL/MallocBinned3.h | |
virtual UE_AUTORTFM_NOAUTORTFM void Free
(
void* Original |
Free | HAL/MallocBinned3.h | |
virtual bool GetAllocationSize
(
void* Original, |
If possible determine the size of the memory allocated at the given address | HAL/MallocBinned3.h | |
virtual const TCHAR * GetDescriptiveName() |
Gets descriptive name for logging purposes. | HAL/MallocBinned3.h | |
virtual bool IsInternallyThreadSafe() |
Returns if the allocator is guaranteed to be thread-safe and therefore doesn't need a unnecessary thread-safety wrapper around it. | HAL/MallocBinned3.h | |
virtual UE_AUTORTFM_NOAUTORTFM void * Malloc
(
SIZE_T Count, |
Malloc | HAL/MallocBinned3.h | |
virtual SIZE_T QuantizeSize
(
SIZE_T Count, |
For some allocators this will return the actual size that should be requested to eliminate internal fragmentation. | HAL/MallocBinned3.h | |
virtual UE_AUTORTFM_NOAUTORTFM void * Realloc
(
void* Original, |
Realloc | HAL/MallocBinned3.h | |
virtual void Trim
(
bool bTrimThreadCaches |
Releases as much memory as possible. Must be called from the main thread. | HAL/MallocBinned3.h | |
virtual void UpdateStats () |
Called once per frame, gathers and sets all memory allocator statistics into the corresponding stats. | HAL/MallocBinned3.h | |
virtual bool ValidateHeap() |
Validates the allocator's heap | HAL/MallocBinned3.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static void * AllocateMetaDataMemory
(
SIZE_T Size |
HAL/MallocBinned3.h | ||
static void FreeMetaDataMemory
(
void* Ptr, |
HAL/MallocBinned3.h |