UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LinearAllocator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "HAL/Platform.h"
6#include "HAL/UnrealMemory.h"
8
9#ifndef UE_ENABLE_LINEAR_VIRTUAL_ALLOCATOR
10# define UE_ENABLE_LINEAR_VIRTUAL_ALLOCATOR PLATFORM_HAS_FPlatformVirtualMemoryBlock
11#endif
12
13
14#if UE_ENABLE_LINEAR_VIRTUAL_ALLOCATOR
15
17{
20 {
21 VirtualMemory.FreeVirtual();
22 }
23
24 CORE_API void* Allocate(SIZE_T Size, uint32 Alignment = 8);
25
26 UE_FORCEINLINE_HINT SIZE_T GetAllocatedMemorySize() const
27 {
28 return Committed;
29 }
30
31protected:
35 SIZE_T Committed = 0;
36 SIZE_T CurrentOffset = 0;
37
38 bool CanFit(SIZE_T Size, uint32 Alignment) const;
39 bool ContainsPointer(const void* Ptr) const;
40};
41
42#else
43
45{
48
49 CORE_API void* Allocate(SIZE_T Size, uint32 Alignment = 8);
50
52 {
53 return TotalAllocated;
54 }
55
56private:
57 struct FBlock
58 {
59 FBlock* Next;
60 SIZE_T BlockSize;
61 };
62
64 FBlock* FirstHeader = nullptr;
65 FBlock* CurrentHeader = nullptr;
66 uint8* CurrentBlock = nullptr;
67 SIZE_T CurrentOffset = 0;
68 SIZE_T CurrentBlockSize = 0;
69 SIZE_T TotalAllocated = 0;
70
71 void AllocateNewBlock(SIZE_T Size);
72 bool CanFit(SIZE_T Size, uint32 Alignment) const;
73};
74
76
77#endif //~UE_ENABLE_LINEAR_VIRTUAL_ALLOCATOR
78
80
86
87// Special case for the FPermanentObjectPoolExtents to reduce the amount of pointer dereferencing
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
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
FLinearBlockAllocator FLinearAllocator
Definition LinearAllocator.h:75
CORE_API FLinearAllocator & GetPersistentLinearAllocator()
Definition LinearAllocator.cpp:163
CORE_API FPersistentLinearAllocatorExtends GPersistentLinearAllocatorExtends
Definition LinearAllocator.cpp:6
FRWLock Lock
Definition UnversionedPropertySerialization.cpp:921
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 AndroidPlatformMemory.h:38
Definition LinearAllocator.h:45
CORE_API void * Allocate(SIZE_T Size, uint32 Alignment=8)
Definition LinearAllocator.cpp:118
CORE_API ~FLinearBlockAllocator()
Definition LinearAllocator.cpp:107
UE_FORCEINLINE_HINT SIZE_T GetAllocatedMemorySize() const
Definition LinearAllocator.h:51
Definition LinearAllocator.h:82
uint64 Address
Definition LinearAllocator.h:83
uint64 Size
Definition LinearAllocator.h:84