UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MallocMimalloc.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreTypes.h"
6#include "HAL/MemoryBase.h"
7
8#if !defined(PLATFORM_BUILDS_MIMALLOC)
9# define PLATFORM_BUILDS_MIMALLOC 0
10#endif
11
12#if !defined(PLATFORM_SUPPORTS_MIMALLOC)
13# define PLATFORM_SUPPORTS_MIMALLOC 0
14#endif
15
16#define MIMALLOC_ENABLED PLATFORM_SUPPORTS_MIMALLOC && MIMALLOC_ALLOCATOR_ALLOWED && PLATFORM_BUILDS_MIMALLOC
17
18#if MIMALLOC_ENABLED
19
23class FMallocMimalloc final
24 : public FMalloc
25{
26public:
27 // FMalloc interface.
29 virtual void* Malloc(SIZE_T Size, uint32 Alignment) override;
30 virtual void* TryMalloc(SIZE_T Size, uint32 Alignment) override;
31 virtual void* Realloc(void* Ptr, SIZE_T NewSize, uint32 Alignment) override;
32 virtual void* TryRealloc(void* Ptr, SIZE_T NewSize, uint32 Alignment) override;
33 virtual void Free(void* Ptr) override;
34 virtual void* MallocZeroed(SIZE_T Count, uint32 Alignment) override;
35 virtual void* TryMallocZeroed(SIZE_T Count, uint32 Alignment) override;
36 virtual bool GetAllocationSize(void *Original, SIZE_T &SizeOut) override;
37 virtual void Trim(bool bTrimThreadCaches) override;
38
39 virtual bool IsInternallyThreadSafe() const override
40 {
41 return true;
42 }
43
44 virtual const TCHAR* GetDescriptiveName( ) override
45 {
46 return TEXT("Mimalloc");
47 }
48
49protected:
50
51 void OutOfMemory( uint64 Size, uint32 Alignment )
52 {
53 // this is expected not to return
55 }
56};
57
58#endif
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32 Size
Definition VulkanMemory.cpp:4034
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition MemoryBase.h:99
virtual const TCHAR * GetDescriptiveName()
Definition MemoryBase.h:248
virtual bool GetAllocationSize(void *Original, SIZE_T &SizeOut)
Definition MemoryBase.h:158
virtual CORE_API void * TryMalloc(SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)
Definition MemoryBase.cpp:95
virtual void * Malloc(SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)=0
virtual CORE_API void * MallocZeroed(SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)
Definition MemoryBase.cpp:105
virtual bool IsInternallyThreadSafe() const
Definition MemoryBase.h:230
virtual CORE_API void * TryRealloc(void *Original, SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)
Definition MemoryBase.cpp:100
virtual void Trim(bool bTrimThreadCaches)
Definition MemoryBase.h:166
virtual void * Realloc(void *Original, SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)=0
virtual CORE_API void * TryMallocZeroed(SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)
Definition MemoryBase.cpp:117
static CORE_API void OnOutOfMemory(uint64 Size, uint32 Alignment)
Definition GenericPlatformMemory.cpp:216