UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
WindowsPlatformMemory.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"
8
9#include <malloc.h>
10
11class FString;
12class FMalloc;
14
20{
27
32
37};
38
39
45{
47 {
48 MCR_Invalid, // not memory
49 MCR_Physical, // main system memory
50 MCR_GPU, // memory directly a GPU (graphics card, etc)
51 MCR_GPUSystem, // system memory directly accessible by a GPU
52 MCR_TexturePool, // presized texture pools
53 MCR_StreamingPool, // amount of texture pool available for streaming.
54 MCR_UsedStreamingPool, // amount of texture pool used for streaming.
55 MCR_GPUDefragPool, // presized pool of memory that can be defragmented.
57 MCR_PhysicalLLM, // total physical memory displayed in the LLM stats (on consoles CPU + GPU)
59 };
60
79
80 //~ Begin FGenericPlatformMemory Interface
81 static CORE_API void Init();
83 {
91 return 32 * 1024 * 1024;
92 }
93
94 static CORE_API class FMalloc* BaseAllocator();
98 static CORE_API bool PageProtect(void* const Ptr, const SIZE_T Size, const bool bCanRead, const bool bCanWrite);
99 static CORE_API void* BinnedAllocFromOS( SIZE_T Size );
100 static CORE_API void BinnedFreeToOS( void* Ptr, SIZE_T Size );
101 static CORE_API void MiMallocInit();
102
104 {
105 public:
106
110
117
118 CORE_API void Commit(size_t InOffset, size_t InSize);
119 CORE_API void Decommit(size_t InOffset, size_t InSize);
120 CORE_API void FreeVirtual();
121
123 {
124 Commit(size_t(((uint8*)InPtr) - ((uint8*)Ptr)), InSize);
125 }
126
128 {
129 Decommit(size_t(((uint8*)InPtr) - ((uint8*)Ptr)), InSize);
130 }
131
133 {
134 Commit(0, GetActualSize());
135 }
136
138 {
140 }
141
146
148 static CORE_API size_t GetCommitAlignment();
149 static CORE_API size_t GetVirtualSizeAlignment();
150 };
151
152 static CORE_API FSharedMemoryRegion* MapNamedSharedMemoryRegion(const FString& InName, bool bCreate, uint32 AccessMode, SIZE_T Size, const void* pSecurityAttributes = nullptr);
153 static CORE_API bool UnmapNamedSharedMemoryRegion(FSharedMemoryRegion * MemoryRegion);
154 static CORE_API bool GetLLMAllocFunctions(void*(*&OutAllocFunction)(size_t), void(*&OutFreeFunction)(void*, size_t), int32& OutAlignment);
155protected:
156 friend struct FGenericStatsUpdater;
157
158 static CORE_API void InternalUpdateStats( const FPlatformMemoryStats& MemoryStats );
159 //~ End FGenericPlatformMemory Interface
160};
161
162
@ BinnedAllocFromOS
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32 Size
Definition VulkanMemory.cpp:4034
FWindowsPlatformMemory FPlatformMemory
Definition WindowsPlatformMemory.h:163
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition GenericPlatformMemory.h:469
void * Ptr
Definition GenericPlatformMemory.h:471
uint32 VMSizeDivVirtualSizeAlignment
Definition GenericPlatformMemory.h:472
Definition MemoryBase.h:99
Definition WindowsPlatformMemory.h:104
CORE_API void FreeVirtual()
Definition WindowsPlatformMemory.cpp:589
UE_FORCEINLINE_HINT void CommitByPtr(void *InPtr, size_t InSize)
Definition WindowsPlatformMemory.h:122
UE_FORCEINLINE_HINT void Decommit()
Definition WindowsPlatformMemory.h:137
UE_FORCEINLINE_HINT size_t GetActualSize() const
Definition WindowsPlatformMemory.h:142
UE_FORCEINLINE_HINT void DecommitByPtr(void *InPtr, size_t InSize)
Definition WindowsPlatformMemory.h:127
static CORE_API FPlatformVirtualMemoryBlock AllocateVirtual(size_t Size, size_t InAlignment=FPlatformVirtualMemoryBlock::GetVirtualSizeAlignment())
Definition WindowsPlatformMemory.cpp:565
FPlatformVirtualMemoryBlock & operator=(const FPlatformVirtualMemoryBlock &Other)=default
FPlatformVirtualMemoryBlock(const FPlatformVirtualMemoryBlock &Other)=default
FPlatformVirtualMemoryBlock(void *InPtr, uint32 InVMSizeDivVirtualSizeAlignment)
Definition WindowsPlatformMemory.h:111
static CORE_API size_t GetCommitAlignment()
Definition WindowsPlatformMemory.cpp:559
UE_FORCEINLINE_HINT void Commit()
Definition WindowsPlatformMemory.h:132
static CORE_API size_t GetVirtualSizeAlignment()
Definition WindowsPlatformMemory.cpp:553
FPlatformVirtualMemoryBlock()
Definition WindowsPlatformMemory.h:107
void * HANDLE
Definition MinimalWindowsApi.h:78
Definition MemoryMisc.h:21
Definition GenericPlatformMemory.h:87
Definition GenericPlatformMemory.h:133
EMemoryPressureStatus
Definition GenericPlatformMemory.h:155
Definition GenericPlatformMemory.h:293
Definition GenericPlatformMemory.h:225
Definition GenericPlatformMemory.cpp:99
Definition AndroidPlatformMemory.h:15
FPlatformMemoryStats()
Definition WindowsPlatformMemory.h:22
EMemoryPressureStatus MemoryPressureStatus
Definition ApplePlatformMemory.h:85
EMemoryPressureStatus GetMemoryPressureStatus() const
Definition WindowsPlatformMemory.h:28
SIZE_T WindowsSpecificMemoryStat
Definition WindowsPlatformMemory.h:34
Definition WindowsPlatformMemory.h:65
Windows::HANDLE GetMapping() const
Definition WindowsPlatformMemory.h:67
FWindowsSharedMemoryRegion(const FString &InName, uint32 InAccessMode, void *InAddress, SIZE_T InSize, Windows::HANDLE InMapping)
Definition WindowsPlatformMemory.h:69
Windows::HANDLE Mapping
Definition WindowsPlatformMemory.h:77
Definition WindowsPlatformMemory.h:45
static CORE_API void GetStatsForMallocProfiler(FGenericMemoryStats &out_Stats)
Definition WindowsPlatformMemory.cpp:423
static CORE_API const FPlatformMemoryConstants & GetConstants()
Definition WindowsPlatformMemory.cpp:435
static CORE_API void MiMallocInit()
Definition WindowsPlatformMemory.cpp:949
static CORE_API bool UnmapNamedSharedMemoryRegion(FSharedMemoryRegion *MemoryRegion)
Definition WindowsPlatformMemory.cpp:730
static CORE_API void Init()
Definition WindowsPlatformMemory.cpp:101
static uint32 GetBackMemoryPoolSize()
Definition WindowsPlatformMemory.h:82
EMemoryCounterRegion
Definition WindowsPlatformMemory.h:47
@ MCR_Physical
Definition WindowsPlatformMemory.h:49
@ MCR_UsedStreamingPool
Definition WindowsPlatformMemory.h:54
@ MCR_StreamingPool
Definition WindowsPlatformMemory.h:53
@ MCR_TexturePool
Definition WindowsPlatformMemory.h:52
@ MCR_GPU
Definition WindowsPlatformMemory.h:50
@ MCR_Invalid
Definition WindowsPlatformMemory.h:48
@ MCR_GPUSystem
Definition WindowsPlatformMemory.h:51
@ MCR_MAX
Definition WindowsPlatformMemory.h:58
@ MCR_GPUDefragPool
Definition WindowsPlatformMemory.h:55
@ MCR_PhysicalLLM
Definition WindowsPlatformMemory.h:57
@ MCR_SamplePlatformSpecifcMemoryRegion
Definition WindowsPlatformMemory.h:56
static CORE_API FSharedMemoryRegion * MapNamedSharedMemoryRegion(const FString &InName, bool bCreate, uint32 AccessMode, SIZE_T Size, const void *pSecurityAttributes=nullptr)
Definition WindowsPlatformMemory.cpp:628
static CORE_API void BinnedFreeToOS(void *Ptr, SIZE_T Size)
Definition WindowsPlatformMemory.cpp:543
static CORE_API bool PageProtect(void *const Ptr, const SIZE_T Size, const bool bCanRead, const bool bCanWrite)
Definition WindowsPlatformMemory.cpp:506
static CORE_API void InternalUpdateStats(const FPlatformMemoryStats &MemoryStats)
Definition WindowsPlatformMemory.cpp:767
static CORE_API FPlatformMemoryStats GetStats()
Definition WindowsPlatformMemory.cpp:300
static CORE_API bool GetLLMAllocFunctions(void *(*&OutAllocFunction)(size_t), void(*&OutFreeFunction)(void *, size_t), int32 &OutAlignment)
static CORE_API class FMalloc * BaseAllocator()
Definition WindowsPlatformMemory.cpp:136