UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MallocStomp.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "HAL/MemoryBase.h"
7
8class FOutputDevice;
9class UWorld;
10
16#if WITH_MALLOC_STOMP
17
18#if PLATFORM_WINDOWS
20#endif
21
28class FMallocStomp final : public FMalloc
29{
30 struct FAllocationData;
31
32 const SIZE_T PageSize;
33
35 const bool bUseUnderrunMode;
36
37 static constexpr SIZE_T VirtualAddressBlockSize = 1 * 1024 * 1024 * 1024; // 1 GB blocks
38
39public:
40 // FMalloc interface.
41 explicit FMallocStomp(const bool InUseUnderrunMode = false);
42
54 virtual void* Malloc(SIZE_T Size, uint32 Alignment) override;
55
56 virtual void* TryMalloc(SIZE_T Size, uint32 Alignment) override;
57
67 virtual void* Realloc(void* InPtr, SIZE_T NewSize, uint32 Alignment) override;
68
69 virtual void* TryRealloc(void* InPtr, SIZE_T NewSize, uint32 Alignment) override;
70
76 virtual void Free(void* InPtr) override;
77
87 virtual bool GetAllocationSize(void *Original, SIZE_T &SizeOut) override;
88
94 virtual void DumpAllocatorStats( FOutputDevice& Ar ) override
95 {
96 // No meaningful stats to dump.
97 }
98
102 virtual bool ValidateHeap() override
103 {
104 // Nothing to do here since validation happens as data is accessed
105 // through page protection, and on each free checking the sentinel.
106 return true;
107 }
108
109#if UE_ALLOW_EXEC_COMMANDS
110 virtual bool Exec( UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar ) override
111 {
112 return false;
113 }
114#endif
115
116 virtual const TCHAR* GetDescriptiveName() override
117 {
118 return TEXT( "Stomp" );
119 }
120
121 virtual bool IsInternallyThreadSafe() const override
122 {
123 // Unix and Mac uses mmap which is thread-safe
124 // Windows uses virtual alloc which is thread-safe
125 // Other platforms using FPlatformMemory::BinnedAllocFromOS are all assumed to have thread-safe implementation already
126 // VirtualAddressCursor and VirtualAddressMax are thread-locals so each thread has its virtual reserved block
127 return true;
128 }
129};
130
131#endif // WITH_MALLOC_STOMP
#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
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
virtual CORE_API bool Exec(UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar)
Definition Exec.cpp:30
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 bool ValidateHeap()
Definition MemoryBase.h:238
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 DumpAllocatorStats(class FOutputDevice &Ar)
Definition MemoryBase.h:221
virtual void * Realloc(void *Original, SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)=0
Definition OutputDevice.h:133
Definition World.h:918