Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
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 "HAL/CriticalSection.h"
7#include "HAL/PlatformMemory.h"
8
10{
11protected:
13 {
14 void* Ptr;
15 SIZE_T ByteSize;
16
18 {
19 Ptr = nullptr;
20 ByteSize = 0;
21 }
22 };
23
24 void* AllocateImpl(SIZE_T Size, uint32 CachedByteLimit, FFreePageBlock* First, FFreePageBlock* Last, uint32& FreedPageBlocksNum, SIZE_T& CachedTotal, FCriticalSection* Mutex);
25 void FreeImpl(void* Ptr, SIZE_T Size, uint32 NumCacheBlocks, uint32 CachedByteLimit, FFreePageBlock* First, uint32& FreedPageBlocksNum, SIZE_T& CachedTotal, FCriticalSection* Mutex, bool ThreadIsTimeCritical);
26 void FreeAllImpl(FFreePageBlock* First, uint32& FreedPageBlocksNum, SIZE_T& CachedTotal, FCriticalSection* Mutex);
27
28 static bool IsOSAllocation(SIZE_T Size, uint32 CachedByteLimit)
29 {
30 return (FPlatformMemory::BinnedPlatformHasMemoryPoolForThisSize(Size) || Size > CachedByteLimit / 4);
31 }
32};
33
34template <uint32 NumCacheBlocks, uint32 CachedByteLimit>
36{
38 : CachedTotal(0)
40 {
41 }
42
43 FORCEINLINE void* Allocate(SIZE_T Size, uint32 AllocationHint = 0, FCriticalSection* Mutex = nullptr)
44 {
46 }
47
48 void Free(void* Ptr, SIZE_T Size, FCriticalSection* Mutex = nullptr, bool ThreadIsTimeCritical = false)
49 {
51 }
52 void FreeAll(FCriticalSection* Mutex = nullptr)
53 {
55 }
56 // Refresh cached os allocator if needed. Does nothing for this implementation
57 void Refresh()
58 {
59
60 }
62 {
63
64 }
66 {
67 return CachedTotal;
68 }
69
70 bool IsOSAllocation(SIZE_T Size)
71 {
73 }
74
75private:
79};
#define FORCEINLINE
Definition Platform.h:644
FWindowsCriticalSection FCriticalSection
FWindowsPlatformMemory FPlatformMemory
static bool IsOSAllocation(SIZE_T Size, uint32 CachedByteLimit)
void FreeAllImpl(FFreePageBlock *First, uint32 &FreedPageBlocksNum, SIZE_T &CachedTotal, FCriticalSection *Mutex)
void * AllocateImpl(SIZE_T Size, uint32 CachedByteLimit, FFreePageBlock *First, FFreePageBlock *Last, uint32 &FreedPageBlocksNum, SIZE_T &CachedTotal, FCriticalSection *Mutex)
void FreeImpl(void *Ptr, SIZE_T Size, uint32 NumCacheBlocks, uint32 CachedByteLimit, FFreePageBlock *First, uint32 &FreedPageBlocksNum, SIZE_T &CachedTotal, FCriticalSection *Mutex, bool ThreadIsTimeCritical)
static bool BinnedPlatformHasMemoryPoolForThisSize(SIZE_T Size)
FFreePageBlock FreedPageBlocks[NumCacheBlocks *2]
bool IsOSAllocation(SIZE_T Size)
FORCEINLINE void * Allocate(SIZE_T Size, uint32 AllocationHint=0, FCriticalSection *Mutex=nullptr)
void FreeAll(FCriticalSection *Mutex=nullptr)
void Free(void *Ptr, SIZE_T Size, FCriticalSection *Mutex=nullptr, bool ThreadIsTimeCritical=false)