Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
MallocBinnedCommon.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "CoreTypes.h"
7#include "HAL/PlatformMemory.h"
8#include "Templates/Function.h"
9
11
12#define BINNEDCOMMON_MAX_LISTED_SMALL_POOL_SIZE 28672
13#define BINNEDCOMMON_NUM_LISTED_SMALL_POOLS 49
14
15#if !defined(BINNEDCOMMON_USE_SEPARATE_VM_PER_POOL)
17 #define BINNEDCOMMON_USE_SEPARATE_VM_PER_POOL (1)
18 #else
19 #define BINNEDCOMMON_USE_SEPARATE_VM_PER_POOL (0)
20 #endif
21#endif
22
23
24class FBitTree
25{
26 uint64* Bits; // one bits in middle layers mean "all allocated"
27 uint32 Capacity; // rounded up to a power of two
28 uint32 DesiredCapacity;
29 uint32 Rows;
30 uint32 OffsetOfLastRow;
31 uint32 AllocationSize;
32
33public:
34 FBitTree()
35 : Bits(nullptr)
36 {
37 }
38
39 static uint32 GetMemoryRequirements(uint32 DesiredCapacity);
40 void FBitTreeInit(uint32 InDesiredCapacity, void * Memory, uint32 MemorySize, bool InitialValue);
41 uint32 AllocBit();
42 bool IsAllocated(uint32 Index) const;
43 void AllocBit(uint32 Index);
44 uint32 NextAllocBit() const;
45 uint32 NextAllocBit(uint32 StartIndex) const;
46 void FreeBit(uint32 Index);
47 uint32 CountOnes(uint32 UpTo) const;
48};
49
50struct FSizeTableEntry
51{
52 uint32 BlockSize;
53 uint16 BlocksPerBlockOfBlocks;
54 uint8 PagesPlatformForBlockOfBlocks;
55
56 FSizeTableEntry()
57 {
58 }
59
60 FSizeTableEntry(uint32 InBlockSize, uint64 PlatformPageSize, uint8 Pages4k, uint32 BasePageSize, uint32 MinimumAlignment);
61
62 bool operator<(const FSizeTableEntry& Other) const
63 {
64 return BlockSize < Other.BlockSize;
65 }
66 static uint8 FillSizeTable(uint64 PlatformPageSize, FSizeTableEntry* SizeTable, uint32 BasePageSize, uint32 MinimumAlignment, uint32 MaxSize, uint32 SizeIncrement);
67};
68
69struct FArenaParams
70{
71 // these are parameters you set
72 uint64 AddressLimit = 1024 * 1024 * 1024; // this controls the size of the root hash table
73 uint32 BasePageSize = 4096; // this is used to make sensible calls to malloc and figures into the standard pool sizes if bUseStandardSmallPoolSizes is true
74 uint32 AllocationGranularity = 4096; // this is the granularity of the commit and decommit calls used on the VM slabs
75 uint32 MaxSizePerBundle = 8192;
76 uint32 MaxStandardPoolSize = 128 * 1024; // these are added to the standard pool sizes, mainly to use the TLS caches, they are typically one block per slab
77 uint16 MaxBlocksPerBundle = 64;
78 uint8 MaxMemoryPerBlockSizeShift = 29;
79 uint8 EmptyCacheAllocExtra = 32;
80 uint8 MaxGlobalBundles = 32;
81 uint8 MinimumAlignmentShift = 4;
82 uint8 PoolCount;
83 bool bUseSeparateVMPerPool = !!(BINNEDCOMMON_USE_SEPARATE_VM_PER_POOL);
84 bool bPerThreadCaches = true;
85 bool bUseStandardSmallPoolSizes = true;
86 bool bAttemptToAlignSmallBocks = true;
87 TArray<uint32> AdditionalBlockSizes;
88
89 // This lambdas is similar to the platform virtual memory HAL and by default just call that.
90 TFunction<FPlatformMemory::FPlatformVirtualMemoryBlock(SIZE_T)> ReserveVM;
91
92 // These allow you to override the large block allocator. The value add here is that MBA tracks the metadata for you and call tell the difference between a large block pointer and a small block pointer.
93 // By defaults these just use the platform VM interface to allocate some committed memory
94 TFunction<void*(SIZE_T, SIZE_T, SIZE_T&, uint32&)> LargeBlockAlloc;
95 TFunction<void(void*, uint32)> LargeBlockFree;
96
97
98 // these are parameters are derived from other parameters
99 uint64 MaxMemoryPerBlockSize;
100 uint32 MaxPoolSize;
101 uint32 MinimumAlignment;
102 uint32 MaximumAlignmentForSmallBlock;
103
104};
105
106
107#endif
#define PLATFORM_HAS_FPlatformVirtualMemoryBlock
Definition Platform.h:537
#define PLATFORM_WINDOWS
Definition Platform.h:4
FWindowsPlatformMemory FPlatformMemory