UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CachedOSPageAllocator.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"
6#include "Misc/OutputDevice.h"
8#include "HAL/PlatformMutex.h"
9
11{
12protected:
14 {
15 void* Ptr;
17
19 {
20 Ptr = nullptr;
21 ByteSize = 0;
22 }
23 };
24
25 void* AllocateImpl(SIZE_T Size, uint32 CachedByteLimit, FFreePageBlock* First, FFreePageBlock* Last, uint32& FreedPageBlocksNum, SIZE_T& CachedTotal, UE::FPlatformRecursiveMutex* Mutex);
26 void FreeImpl(void* Ptr, SIZE_T Size, uint32 NumCacheBlocks, uint32 CachedByteLimit, FFreePageBlock* First, uint32& FreedPageBlocksNum, SIZE_T& CachedTotal, UE::FPlatformRecursiveMutex* Mutex, bool ThreadIsTimeCritical);
27 void FreeAllImpl(FFreePageBlock* First, uint32& FreedPageBlocksNum, SIZE_T& CachedTotal, UE::FPlatformRecursiveMutex* Mutex);
28
33};
34
35template <uint32 NumCacheBlocks, uint32 CachedByteLimit>
37{
39 : CachedTotal(0)
40 , FreedPageBlocksNum(0)
41 {
42 }
43
45 {
46 return AllocateImpl(Size, CachedByteLimit, FreedPageBlocks, FreedPageBlocks + FreedPageBlocksNum, FreedPageBlocksNum, CachedTotal, Mutex);
47 }
48
49 void Free(void* Ptr, SIZE_T Size, UE::FPlatformRecursiveMutex* Mutex = nullptr, bool ThreadIsTimeCritical = false)
50 {
51 return FreeImpl(Ptr, Size, ThreadIsTimeCritical ? NumCacheBlocks*2 : NumCacheBlocks, CachedByteLimit, FreedPageBlocks, FreedPageBlocksNum, CachedTotal, Mutex, ThreadIsTimeCritical);
52 }
53
54 void FreeAll(UE::FPlatformRecursiveMutex* Mutex = nullptr)
55 {
56 return FreeAllImpl(FreedPageBlocks, FreedPageBlocksNum, CachedTotal, Mutex);
57 }
58
59 // Refresh cached os allocator if needed. Does nothing for this implementation
60 void Refresh()
61 {
62 }
63
65 {
66 }
67
69 {
70 return CachedTotal;
71 }
72
77
82
84 {
85 Ar.Logf(TEXT("CachedOSPageAllocator = %fkb"), (double)GetCachedFreeTotal() / 1024.0);
86 }
87
88private:
89 FFreePageBlock FreedPageBlocks[NumCacheBlocks*2];
90 SIZE_T CachedTotal;
91 uint32 FreedPageBlocksNum;
92};
93
94#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_7
95#include "HAL/CriticalSection.h"
96#endif
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
#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
uint32 Size
Definition VulkanMemory.cpp:4034
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition OutputDevice.h:133
void Logf(const FmtType &Fmt)
Definition OutputDevice.h:234
FPThreadsRecursiveMutex FPlatformRecursiveMutex
Definition AndroidPlatformMutex.h:12
Definition CachedOSPageAllocator.h:14
void * Ptr
Definition CachedOSPageAllocator.h:15
FFreePageBlock()
Definition CachedOSPageAllocator.h:18
SIZE_T ByteSize
Definition CachedOSPageAllocator.h:16
Definition CachedOSPageAllocator.h:11
static bool IsOSAllocation(SIZE_T Size, uint32 CachedByteLimit)
Definition CachedOSPageAllocator.h:29
void * AllocateImpl(SIZE_T Size, uint32 CachedByteLimit, FFreePageBlock *First, FFreePageBlock *Last, uint32 &FreedPageBlocksNum, SIZE_T &CachedTotal, UE::FPlatformRecursiveMutex *Mutex)
Definition CachedOSPageAllocator.cpp:11
void FreeAllImpl(FFreePageBlock *First, uint32 &FreedPageBlocksNum, SIZE_T &CachedTotal, UE::FPlatformRecursiveMutex *Mutex)
Definition CachedOSPageAllocator.cpp:131
void FreeImpl(void *Ptr, SIZE_T Size, uint32 NumCacheBlocks, uint32 CachedByteLimit, FFreePageBlock *First, uint32 &FreedPageBlocksNum, SIZE_T &CachedTotal, UE::FPlatformRecursiveMutex *Mutex, bool ThreadIsTimeCritical)
Definition CachedOSPageAllocator.cpp:94
static bool BinnedPlatformHasMemoryPoolForThisSize(SIZE_T Size)
Definition GenericPlatformMemory.h:548
Definition CachedOSPageAllocator.h:37
void FreeAll(UE::FPlatformRecursiveMutex *Mutex=nullptr)
Definition CachedOSPageAllocator.h:54
void UpdateStats()
Definition CachedOSPageAllocator.h:64
void Refresh()
Definition CachedOSPageAllocator.h:60
void DumpAllocatorStats(class FOutputDevice &Ar)
Definition CachedOSPageAllocator.h:83
uint64 GetCachedFreeTotal() const
Definition CachedOSPageAllocator.h:68
UE_FORCEINLINE_HINT void * Allocate(SIZE_T Size, uint32 AllocationHint=0, UE::FPlatformRecursiveMutex *Mutex=nullptr)
Definition CachedOSPageAllocator.h:44
void Free(void *Ptr, SIZE_T Size, UE::FPlatformRecursiveMutex *Mutex=nullptr, bool ThreadIsTimeCritical=false)
Definition CachedOSPageAllocator.h:49
uint64 GetCachedImmediatelyFreeable() const
Definition CachedOSPageAllocator.h:73
bool IsOSAllocation(SIZE_T Size)
Definition CachedOSPageAllocator.h:78
TCachedOSPageAllocator()
Definition CachedOSPageAllocator.h:38