UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UnixPlatformMemory.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================================
4 UnixPlatformMemory.h: Unix platform memory functions
5==============================================================================================*/
6
7#pragma once
8
9#include "CoreTypes.h"
11#include "HAL/PlatformCrt.h"
12
13#include <malloc.h>
14
15class FString;
16
17#ifndef COMPILE_FORK_PAGE_PROTECTOR
18 #define COMPILE_FORK_PAGE_PROTECTOR 0
19#endif
20
25{};
26
50
55{
60 {
62 int GetFileDescriptor() const { return Fd; }
63
65 bool NeedsToUnlinkRegion() const { return bCreatedThisRegion; }
66
72
73 protected:
74
76 int Fd;
77
80 };
81
82 //~ Begin FGenericPlatformMemory Interface
83 static CORE_API void Init();
84 static CORE_API class FMalloc* BaseAllocator();
88 static CORE_API bool PageProtect(void* const Ptr, const SIZE_T Size, const bool bCanRead, const bool bCanWrite);
90 static CORE_API void BinnedFreeToOS(void* Ptr, SIZE_T Size);
91
93
95 {
96 public:
97
101
108
109 CORE_API void Commit(size_t InOffset, size_t InSize);
110 CORE_API void Decommit(size_t InOffset, size_t InSize);
111 CORE_API void FreeVirtual();
112
114 {
115 Commit(size_t(((uint8*)InPtr) - ((uint8*)Ptr)), InSize);
116 }
117
119 {
120 Decommit(size_t(((uint8*)InPtr) - ((uint8*)Ptr)), InSize);
121 }
122
124 {
125 Commit(0, GetActualSize());
126 }
127
129 {
131 }
132
137
139 static CORE_API size_t GetCommitAlignment();
140 static CORE_API size_t GetVirtualSizeAlignment();
141 };
142
143 static CORE_API FSharedMemoryRegion * MapNamedSharedMemoryRegion(const FString& InName, bool bCreate, uint32 AccessMode, SIZE_T Size);
144 static CORE_API bool UnmapNamedSharedMemoryRegion(FSharedMemoryRegion * MemoryRegion);
145 static CORE_API bool GetLLMAllocFunctions(void*(*&OutAllocFunction)(size_t), void(*&OutFreeFunction)(void*, size_t), int32& OutAlignment);
146 [[noreturn]] static CORE_API void OnOutOfMemory(uint64 Size, uint32 Alignment);
147 //~ End FGenericPlatformMemory Interface
148
150
152};
153
155
156
157
@ 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
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
FUnixPlatformMemory FPlatformMemory
Definition UnixPlatformMemory.h:154
uint32 Size
Definition VulkanMemory.cpp:4034
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 UnixPlatformMemory.h:95
static CORE_API size_t GetVirtualSizeAlignment()
Definition UnixPlatformMemory.cpp:607
FPlatformVirtualMemoryBlock(const FPlatformVirtualMemoryBlock &Other)=default
static CORE_API FPlatformVirtualMemoryBlock AllocateVirtual(size_t Size, size_t InAlignment=FPlatformVirtualMemoryBlock::GetVirtualSizeAlignment())
Definition UnixPlatformMemory.cpp:619
UE_FORCEINLINE_HINT void CommitByPtr(void *InPtr, size_t InSize)
Definition UnixPlatformMemory.h:113
UE_FORCEINLINE_HINT size_t GetActualSize() const
Definition UnixPlatformMemory.h:133
CORE_API void FreeVirtual()
Definition UnixPlatformMemory.cpp:645
UE_FORCEINLINE_HINT void DecommitByPtr(void *InPtr, size_t InSize)
Definition UnixPlatformMemory.h:118
static CORE_API size_t GetCommitAlignment()
Definition UnixPlatformMemory.cpp:613
FPlatformVirtualMemoryBlock(void *InPtr, uint32 InVMSizeDivVirtualSizeAlignment)
Definition UnixPlatformMemory.h:102
UE_FORCEINLINE_HINT void Decommit()
Definition UnixPlatformMemory.h:128
FPlatformVirtualMemoryBlock()
Definition UnixPlatformMemory.h:98
UE_FORCEINLINE_HINT void Commit()
Definition UnixPlatformMemory.h:123
FPlatformVirtualMemoryBlock & operator=(const FPlatformVirtualMemoryBlock &Other)=default
Definition Array.h:670
Definition UnixPlatformMemory.h:31
SIZE_T KSM_Process_Profit
Definition UnixPlatformMemory.h:45
SIZE_T Private_Dirty
Definition UnixPlatformMemory.h:42
SIZE_T Shared_Dirty
Definition UnixPlatformMemory.h:36
SIZE_T Private_Clean
Definition UnixPlatformMemory.h:39
SIZE_T Shared_Clean
Definition UnixPlatformMemory.h:33
bool bIs_KSM_Enabled
Definition UnixPlatformMemory.h:48
Definition GenericPlatformMemory.h:87
Definition GenericPlatformMemory.h:133
Definition GenericPlatformMemory.h:293
Definition GenericPlatformMemory.h:225
Definition AndroidPlatformMemory.h:15
Definition UnixPlatformMemory.h:60
bool bCreatedThisRegion
Definition UnixPlatformMemory.h:79
int GetFileDescriptor() const
Definition UnixPlatformMemory.h:62
bool NeedsToUnlinkRegion() const
Definition UnixPlatformMemory.h:65
int Fd
Definition UnixPlatformMemory.h:76
FUnixSharedMemoryRegion(const FString &InName, uint32 InAccessMode, void *InAddress, SIZE_T InSize, int InFd, bool bInCreatedThisRegion)
Definition UnixPlatformMemory.h:67
Definition UnixPlatformMemory.h:55
static CORE_API void OnOutOfMemory(uint64 Size, uint32 Alignment)
Definition UnixPlatformMemory.cpp:1387
static CORE_API const FPlatformMemoryConstants & GetConstants()
Definition UnixPlatformMemory.cpp:1222
static CORE_API class FMalloc * BaseAllocator()
Definition UnixPlatformMemory.cpp:133
static CORE_API bool CanOverallocateVirtualMemory()
Definition UnixPlatformMemory.cpp:1474
static CORE_API bool HasForkPageProtectorEnabled()
Definition UnixPlatformMemory.cpp:128
static CORE_API FSharedMemoryRegion * MapNamedSharedMemoryRegion(const FString &InName, bool bCreate, uint32 AccessMode, SIZE_T Size)
Definition UnixPlatformMemory.cpp:1254
static CORE_API void Init()
Definition UnixPlatformMemory.cpp:103
static CORE_API bool GetForkedPageAllocationInfo(TArray< FForkedPageAllocation > &OutPageAllocationInfos)
Definition UnixPlatformMemory.cpp:1057
static CORE_API bool UnmapNamedSharedMemoryRegion(FSharedMemoryRegion *MemoryRegion)
Definition UnixPlatformMemory.cpp:1341
static CORE_API void BinnedFreeToOS(void *Ptr, SIZE_T Size)
Definition UnixPlatformMemory.cpp:541
static CORE_API FPlatformMemoryStats GetStats()
Definition UnixPlatformMemory.cpp:870
static CORE_API FExtendedPlatformMemoryStats GetExtendedStats()
Definition UnixPlatformMemory.cpp:1134
static CORE_API bool PageProtect(void *const Ptr, const SIZE_T Size, const bool bCanRead, const bool bCanWrite)
Definition UnixPlatformMemory.cpp:361
static CORE_API bool GetLLMAllocFunctions(void *(*&OutAllocFunction)(size_t), void(*&OutFreeFunction)(void *, size_t), int32 &OutAlignment)
Definition UnixPlatformMemory.cpp:1462