UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MemoryTrace.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "HAL/Platform.h"
6#include "Trace/Config.h"
7#include "Trace/Trace.h"
8
9#if !defined(UE_MEMORY_TRACE_AVAILABLE)
10# define UE_MEMORY_TRACE_AVAILABLE 0
11#endif
12
13#if !defined(UE_MEMORY_TRACE_LATE_INIT)
14# define UE_MEMORY_TRACE_LATE_INIT 0
15#endif
16
17#if !defined(UE_MEMORY_TRACE_ENABLED) && UE_TRACE_ENABLED
18# if UE_MEMORY_TRACE_AVAILABLE
19# if !PLATFORM_USES_FIXED_GMalloc_CLASS && PLATFORM_64BITS
20# define UE_MEMORY_TRACE_ENABLED !UE_BUILD_SHIPPING
21# endif
22# endif
23#endif
24
25#if !defined(UE_MEMORY_TRACE_ENABLED)
26# define UE_MEMORY_TRACE_ENABLED 0
27#endif
28
30typedef uint32 HeapId;
31
40
42// These values are traced. Do not modify existing values in order to maintain
43// compatibility.
45{
46 None = 0,
47 Root = 1 << 0,
48 NeverFrees = 1 << 1, // The heap doesn't free (e.g. linear allocator)
49};
51
53// These values are traced. Do not modify existing values in order to maintain
54// compatibility.
56{
57 None = 0,
58 Heap = 1 << 0, // Is a heap, can be used to unmark alloc as heap.
59 Swap = 2 << 0, // Is a swap page
60};
62
65{
66 PageOut = 0, // Paged out to swap
67 PageIn = 1, // Read from swap via page fault
68 FreeInSwap = 2, // Freed while being paged out in swap
69};
70
72
73// Internal options for early initialization of memory tracing systems. Exposed
74// here due to visibility in platform implementations.
76{
77 Disabled = 0,
78 AllocEvents = 1 << 0,
79 Callstacks = 1 << 1,
80 Tags = 1 << 2,
81 Probing = 1 << 3,
84};
85
87
89#if UE_MEMORY_TRACE_ENABLED
90
91#define UE_MEMORY_TRACE(x) x
92
94
98
104
113
121
130
139
149
157
165
174
182
190
192#else // UE_MEMORY_TRACE_ENABLED
193
194#define UE_MEMORY_TRACE(x)
204inline void MemoryTrace_SwapOp(uint64 PageAddress, EMemoryTraceSwapOperation SwapOperation, uint32 CompressedSize = 0, uint32 CallstackId = 0) {}
205inline class FMalloc* MemoryTrace_GetAllocator() { return nullptr; }
206
207#endif // UE_MEMORY_TRACE_ENABLED
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
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
HeapId MemoryTrace_RootHeapSpec(const TCHAR *Name, EMemoryTraceHeapFlags Flags=EMemoryTraceHeapFlags::None)
Definition MemoryTrace.h:195
void MemoryTrace_MarkAllocAsHeap(uint64 Address, HeapId Heap)
Definition MemoryTrace.h:197
void MemoryTrace_SwapOp(uint64 PageAddress, EMemoryTraceSwapOperation SwapOperation, uint32 CompressedSize=0, uint32 CallstackId=0)
Definition MemoryTrace.h:204
HeapId MemoryTrace_HeapSpec(HeapId ParentId, const TCHAR *Name, EMemoryTraceHeapFlags Flags=EMemoryTraceHeapFlags::None)
Definition MemoryTrace.h:196
void MemoryTrace_UpdateAlloc(uint64 Address, HeapId RootHeap=EMemoryTraceRootHeap::SystemMemory, uint32 ExternalCallstackId=0)
Definition MemoryTrace.h:203
class FMalloc * MemoryTrace_GetAllocator()
Definition MemoryTrace.h:205
EMemoryTraceSwapOperation
Definition MemoryTrace.h:65
void MemoryTrace_Free(uint64 Address, HeapId RootHeap=EMemoryTraceRootHeap::SystemMemory, uint32 ExternalCallstackId=0)
Definition MemoryTrace.h:200
void MemoryTrace_ReallocAlloc(uint64 Address, uint64 NewSize, uint32 Alignment, HeapId RootHeap=EMemoryTraceRootHeap::SystemMemory, uint32 ExternalCallstackId=0)
Definition MemoryTrace.h:202
uint32 HeapId
Definition MemoryTrace.h:30
EMemoryTraceHeapFlags
Definition MemoryTrace.h:45
EMemoryTraceRootHeap
Definition MemoryTrace.h:34
@ SystemMemory
Definition MemoryTrace.h:35
@ EndHardcoded
Definition MemoryTrace.h:37
@ EndReserved
Definition MemoryTrace.h:38
@ VideoMemory
Definition MemoryTrace.h:36
EMemoryTraceInit
Definition MemoryTrace.h:76
EMemoryTraceHeapAllocationFlags
Definition MemoryTrace.h:56
void MemoryTrace_UnmarkAllocAsHeap(uint64 Address, HeapId Heap)
Definition MemoryTrace.h:198
void MemoryTrace_Alloc(uint64 Address, uint64 Size, uint32 Alignment, HeapId RootHeap=EMemoryTraceRootHeap::SystemMemory, uint32 ExternalCallstackId=0)
Definition MemoryTrace.h:199
void MemoryTrace_ReallocFree(uint64 Address, HeapId RootHeap=EMemoryTraceRootHeap::SystemMemory, uint32 ExternalCallstackId=0)
Definition MemoryTrace.h:201
#define UE_TRACE_CHANNEL_EXTERN(ChannelName,...)
Definition Trace.h:448
uint32 Size
Definition VulkanMemory.cpp:4034
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition MemoryBase.h:99