UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MemoryMisc.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"
7#include "Containers/Map.h"
10
11#ifndef UE_MEMORY_STAT_DESCRIPTION_LENGTH_DEFAULT
12#define UE_MEMORY_STAT_DESCRIPTION_LENGTH 64
13#endif
14
15#ifndef UE_MEMORY_STAT_PREALLOCATION_COUNT
16#define UE_MEMORY_STAT_PREALLOCATION_COUNT 32
17#endif
18
21{
22private:
24 static constexpr int32 EntryCount = UE_MEMORY_STAT_PREALLOCATION_COUNT;
25 static constexpr int32 StringLength = UE_MEMORY_STAT_DESCRIPTION_LENGTH;
27
28public:
30 {
31 const FStringView DescriptionView = Descriptions.Emplace_GetRef(InPlace, InDescription).ToView();
32 Data.FInternalMap::Add(DescriptionView, InValue);
33 }
34
36 {
37 return Data.FInternalMap::Find(InDescription);
38 }
39
40 const SIZE_T* Find(const FStringView& InDescription) const
41 {
42 return const_cast<FGenericMemoryStats*>(this)->Find(InDescription);
43 }
44
46 {
47 return Data.FInternalMap::FindRef(InDescription);
48 }
49
50 // Expose iterators only for const ranged-for iteration
51 FInternalMap::TRangedForConstIterator begin() const { return Data.begin(); }
52 FInternalMap::TRangedForConstIterator end() const { return Data.end(); }
53
54private:
56
58 class FGenericMemoryStatsMap : public FInternalMap
59 {
60 public:
61 SIZE_T* Find(const FString& InDescription)
62 {
64 return FInternalMap::Find(DescriptionView);
65 }
66
67 const SIZE_T* Find(const FString& InDescription) const
68 {
69 return const_cast<FGenericMemoryStatsMap*>(this)->Find(InDescription);
70 }
71
72 SIZE_T FindRef(const FString& InDescription) const
73 {
75 return FInternalMap::FindRef(DescriptionView);
76 }
77 };
79
80public:
81 UE_DEPRECATED(5.5, "Using Data directly is deprecated and will be made private. Use methods on FGenericMemoryStats directly.")
82 FGenericMemoryStatsMap Data;
83};
84
85#ifndef ENABLE_MEMORY_SCOPE_STATS
86#define ENABLE_MEMORY_SCOPE_STATS 0
87#endif
88
89// This will grab the memory stats of VM and Physical before and at the end of scope
90// reporting +/- difference in memory.
91// WARNING This will also capture differences in Threads which have nothing to do with the scope
92#if ENABLE_MEMORY_SCOPE_STATS
94{
95public:
96 CORE_API explicit FScopedMemoryStats(const TCHAR* Name);
97
99
100private:
101 const TCHAR* Text;
103};
104#else
106{
107public:
108 explicit FScopedMemoryStats(const TCHAR* Name) {}
109};
110#endif
111
117#ifndef ENABLE_SHARED_MEMORY_TRACKER
118#define ENABLE_SHARED_MEMORY_TRACKER 0
119#endif
120
121#if ENABLE_SHARED_MEMORY_TRACKER && PLATFORM_UNIX
122
124{
125public:
126
128 static CORE_API void PrintMemoryDiff(const TCHAR* Context);
129
130
132 CORE_API explicit FSharedMemoryTracker(const FString& InContext);
134
135private:
136 const FString PrintContext;
138};
139#else
141{
142public:
143
144 static void PrintMemoryDiff(const TCHAR* /*Context*/) {}
145
146 explicit FSharedMemoryTracker(const FString& /*InContext*/) {}
147};
148#endif // ENABLE_SHARED_MEMORY_TRACKER && PLATFORM_UNIX
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
@ InPlace
Definition CoreMiscDefines.h:162
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::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:12
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:8
#define UE_MEMORY_STAT_PREALLOCATION_COUNT
Definition MemoryMisc.h:16
#define UE_MEMORY_STAT_DESCRIPTION_LENGTH
Definition MemoryMisc.h:12
Definition MemoryMisc.h:106
FScopedMemoryStats(const TCHAR *Name)
Definition MemoryMisc.h:108
Definition MemoryMisc.h:141
static void PrintMemoryDiff(const TCHAR *)
Definition MemoryMisc.h:144
FSharedMemoryTracker(const FString &)
Definition MemoryMisc.h:146
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition ContainerAllocationPolicies.h:894
Definition UnixPlatformMemory.h:31
Definition MemoryMisc.h:21
const SIZE_T * Find(const FStringView &InDescription) const
Definition MemoryMisc.h:40
FInternalMap::TRangedForConstIterator begin() const
Definition MemoryMisc.h:51
void Add(const FStringView &InDescription, SIZE_T InValue)
Definition MemoryMisc.h:29
FInternalMap::TRangedForConstIterator end() const
Definition MemoryMisc.h:52
FGenericMemoryStatsMap Data
Definition MemoryMisc.h:82
SIZE_T * Find(const FStringView &InDescription)
Definition MemoryMisc.h:35
SIZE_T FindRef(const FStringView &InDescription) const
Definition MemoryMisc.h:45
Definition AndroidPlatformMemory.h:15