Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
WindowsPlatformMemory.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "API/UE/CoreTypes.h"
6#include "API/UE/GenericPlatform/GenericPlatformMemory.h"
7#include "API/UE/Windows/WindowsSystemIncludes.h"
8
9#include <malloc.h>
10
11class FString;
12class FMalloc;
14
15/**
16 * Windows implementation of the FGenericPlatformMemoryStats.
17 */
20{
21 /** Default constructor, clears all variables. */
26 { }
27
29 {
31 }
32
33 /** Example of a memory stat that is specific to Windows. */
35 /** Status reported by QueryMemoryResourceNotification. */
37};
38
39
40/**
41* Windows implementation of the memory OS functions
42**/
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
61 /**
62 * Windows representation of a shared memory region
63 */
65 {
66 /** Returns the handle to file mapping object. */
67 Windows::HANDLE GetMapping() const { return Mapping; }
68
69 FWindowsSharedMemoryRegion(const FString& InName, uint32 InAccessMode, void* InAddress, SIZE_T InSize, Windows::HANDLE InMapping)
70 : FSharedMemoryRegion(InName, InAccessMode, InAddress, InSize)
71 , Mapping(InMapping)
72 {}
73
74 protected:
75
76 /** Handle of a file mapping object */
78 };
79
80 //~ Begin FGenericPlatformMemory Interface
81 static void Init();
82 static uint32 GetBackMemoryPoolSize()
83 {
84 /**
85 * Value determined by series of tests on Fortnite with limited process memory.
86 * 26MB sufficed to report all test crashes, using 32MB to have some slack.
87 * If this pool is too large, use the following values to determine proper size:
88 * 2MB pool allowed to report 78% of crashes.
89 * 6MB pool allowed to report 90% of crashes.
90 */
91 return 32 * 1024 * 1024;
92 }
93
94 static class FMalloc* BaseAllocator();
98 static bool PageProtect(void* const Ptr, const SIZE_T Size, const bool bCanRead, const bool bCanWrite);
99 static void* BinnedAllocFromOS( SIZE_T Size );
100 static void BinnedFreeToOS( void* Ptr, SIZE_T Size );
101 static void MiMallocInit();
102
104 {
105 public:
106
108 {
109 }
110
111 FPlatformVirtualMemoryBlock(void *InPtr, uint32 InVMSizeDivVirtualSizeAlignment)
112 : FBasicVirtualMemoryBlock(InPtr, InVMSizeDivVirtualSizeAlignment)
113 {
114 }
117
118 void Commit(size_t InOffset, size_t InSize);
119 void Decommit(size_t InOffset, size_t InSize);
121
122 FORCEINLINE void CommitByPtr(void *InPtr, size_t InSize)
123 {
124 Commit(size_t(((uint8*)InPtr) - ((uint8*)Ptr)), InSize);
125 }
126
127 FORCEINLINE void DecommitByPtr(void *InPtr, size_t InSize)
128 {
129 Decommit(size_t(((uint8*)InPtr) - ((uint8*)Ptr)), InSize);
130 }
131
133 {
135 }
136
138 {
140 }
141
143 {
145 }
146
148 static size_t GetCommitAlignment();
149 static size_t GetVirtualSizeAlignment();
150 };
151
152 static FSharedMemoryRegion* MapNamedSharedMemoryRegion(const FString& InName, bool bCreate, uint32 AccessMode, SIZE_T Size, const void* pSecurityAttributes = nullptr);
154 static bool GetLLMAllocFunctions(void*(*&OutAllocFunction)(size_t), void(*&OutFreeFunction)(void*, size_t), int32& OutAlignment);
155protected:
156 friend struct FGenericStatsUpdater;
157
158 static void InternalUpdateStats( const FPlatformMemoryStats& MemoryStats );
159 //~ End FGenericPlatformMemory Interface
160};
161
162
FGenericPlatformMemoryConstants FPlatformMemoryConstants
#define FORCEINLINE
Definition Platform.h:644
FWindowsPlatformMemory FPlatformMemory
FBasicVirtualMemoryBlock(void *InPtr, uint32 InVMSizeDivVirtualSizeAlignment)
void Decommit(size_t InOffset, size_t InSize)
FORCEINLINE void DecommitByPtr(void *InPtr, size_t InSize)
FORCEINLINE void CommitByPtr(void *InPtr, size_t InSize)
FPlatformVirtualMemoryBlock & operator=(const FPlatformVirtualMemoryBlock &Other)=default
FPlatformVirtualMemoryBlock(const FPlatformVirtualMemoryBlock &Other)=default
static FPlatformVirtualMemoryBlock AllocateVirtual(size_t Size, size_t InAlignment=FPlatformVirtualMemoryBlock::GetVirtualSizeAlignment())
FPlatformVirtualMemoryBlock(void *InPtr, uint32 InVMSizeDivVirtualSizeAlignment)
void Commit(size_t InOffset, size_t InSize)
FSharedMemoryRegion(const FString &InName, uint32 InAccessMode, void *InAddress, SIZE_T InSize)
EMemoryPressureStatus MemoryPressureStatus
EMemoryPressureStatus GetMemoryPressureStatus() const
FWindowsSharedMemoryRegion(const FString &InName, uint32 InAccessMode, void *InAddress, SIZE_T InSize, Windows::HANDLE InMapping)
static void InternalUpdateStats(const FPlatformMemoryStats &MemoryStats)
static void * BinnedAllocFromOS(SIZE_T Size)
static bool UnmapNamedSharedMemoryRegion(FSharedMemoryRegion *MemoryRegion)
static void BinnedFreeToOS(void *Ptr, SIZE_T Size)
static const FPlatformMemoryConstants & GetConstants()
static uint32 GetBackMemoryPoolSize()
static bool GetLLMAllocFunctions(void *(*&OutAllocFunction)(size_t), void(*&OutFreeFunction)(void *, size_t), int32 &OutAlignment)
static FSharedMemoryRegion * MapNamedSharedMemoryRegion(const FString &InName, bool bCreate, uint32 AccessMode, SIZE_T Size, const void *pSecurityAttributes=nullptr)
static class FMalloc * BaseAllocator()
static void GetStatsForMallocProfiler(FGenericMemoryStats &out_Stats)
static FPlatformMemoryStats GetStats()
static void MiMallocInit()
static bool PageProtect(void *const Ptr, const SIZE_T Size, const bool bCanRead, const bool bCanWrite)