5#include "Containers/Array.h"
59 SIZE_T BlockSize = 1 << 16;
61 std::atomic<int32> ReferenceCount{ 0 };
106 checkf(ReferenceCount.load(std::memory_order_relaxed) == 0,
107 TEXT(
"FLinearBlockAllocator is destroyed while still in use by a FLinearBlockAllocatorThreadAccessor."));
116 checkf(ReferenceCount.load(std::memory_order_relaxed) == 0,
117 TEXT(
"FLinearBlockAllocator::Malloc is being used directly while in use by a FLinearBlockAllocatorThreadAccessor, this is not allowed, all malloc calls must go through a FLinearBlockAllocatorThreadAccessor."));
119 void* Result = TryAllocateFromBlock(
Size, Alignment, LastBlock);
125 if (RequiresCustomAllocation(
Size, Alignment))
127 return GetCustomAllocation(
Size, Alignment);
130 LastBlock = GetNewBlock();
131 Result = TryAllocateFromBlock(
Size, Alignment, LastBlock);
136inline void* FLinearBlockAllocator::TryAllocateFromBlock(
SIZE_T Size,
uint32 Alignment,
156bool FLinearBlockAllocator::RequiresCustomAllocation(
SIZE_T Size,
uint32 Alignment)
const
184void* FLinearBlockAllocator::GetCustomAllocation(
SIZE_T Size,
uint32 Alignment)
196 Allocator.ReferenceCount.fetch_add(1, std::memory_order_relaxed);
201 Allocator.ReferenceCount.fetch_add(-1, std::memory_order_relaxed);
206 void* Result = Allocator.TryAllocateFromBlock(
Size, Alignment, LastBlock);
214 if (Allocator.RequiresCustomAllocation(
Size, Alignment))
216 return Allocator.GetCustomAllocation(
Size, Alignment);
218 LastBlock = Allocator.GetNewBlock();
220 Result = Allocator.TryAllocateFromBlock(
Size, Alignment, LastBlock);
constexpr T Align(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:18
#define check(expr)
Definition AssertionMacros.h:314
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
uint32 Size
Definition VulkanMemory.cpp:4034
Definition ScopeLock.h:141
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
Definition LinearBlockAllocator.h:79
~FLinearBlockAllocatorThreadAccessor()
Definition LinearBlockAllocator.h:199
void * Malloc(SIZE_T Size, uint32 Alignment)
Definition LinearBlockAllocator.h:204
FLinearBlockAllocatorThreadAccessor(FLinearBlockAllocator &InAllocator)
Definition LinearBlockAllocator.h:193
Definition LinearBlockAllocator.h:44
~FLinearBlockAllocator()
Definition LinearBlockAllocator.h:102
void * Malloc(SIZE_T Size, uint32 Alignment)
Definition LinearBlockAllocator.h:114
Definition LinearBlockAllocator.h:15
Definition AdvancedWidgetsModule.cpp:13
static FORCENOINLINE CORE_API void Free(void *Original)
Definition UnrealMemory.cpp:685
Definition LinearBlockAllocator.h:18
int32 NextOffset
Definition LinearBlockAllocator.h:19