UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GrowOnlySpanAllocator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6
8{
9public:
10
12 MaxSize(0)
13 {}
14
15 // Allocate a range. Returns allocated StartOffset.
17
18 // Free an already allocated range.
19 ENGINE_API void Free(int32 BaseOffset, int32 Num);
20
22 {
23 int32 AllocatedSize = MaxSize;
24
25 for (int32 i = 0; i < FreeSpans.Num(); i++)
26 {
27 AllocatedSize -= FreeSpans[i].Num;
28 }
29
30 return AllocatedSize;
31 }
32
34 {
35 return MaxSize;
36 }
37
39 {
40 return FreeSpans.Num();
41 }
42
43#if DO_CHECK
48 inline bool IsFree(int32 Index) const
49 {
50 // If outside the max size, it is considered free as the allocator can grow at will
51 if (Index >= MaxSize)
52 {
53 return true;
54 }
55
56 for (const auto& FreeSpan : FreeSpans)
57 {
58 if (Index >= FreeSpan.StartOffset && Index < FreeSpan.StartOffset + FreeSpan.Num)
59 {
60 return true;
61 }
62 }
63
64 return false;
65 }
66#endif // DO_CHECK
67
74
75private:
76 class FLinearAllocation
77 {
78 public:
79
80 FLinearAllocation(int32 InStartOffset, int32 InNum) :
81 StartOffset(InStartOffset),
82 Num(InNum)
83 {}
84
85 int32 StartOffset;
86 int32 Num;
87
88 bool Contains(FLinearAllocation Other)
89 {
90 return StartOffset <= Other.StartOffset && (StartOffset + Num) >= (Other.StartOffset + Other.Num);
91 }
92
93 bool operator<(const FLinearAllocation& Other) const
94 {
95 return StartOffset < Other.StartOffset;
96 }
97 };
98
99 // Size of the linear range used by the allocator
100 int32 MaxSize;
101
102 // Unordered free list
104
105 bool bDeferMerges = false;
106
107 ENGINE_API int32 SearchFreeList(int32 Num);
108};
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
bool operator<(const FTextFormatString &LHS, const FTextFormatString &RHS)
Definition ITextFormatArgumentModifier.h:147
@ Num
Definition MetalRHIPrivate.h:234
Definition GrowOnlySpanAllocator.h:8
FGrowOnlySpanAllocator()
Definition GrowOnlySpanAllocator.h:11
ENGINE_API int32 Allocate(int32 Num)
Definition GrowOnlySpanAllocator.cpp:8
int32 GetNumFreeSpans() const
Definition GrowOnlySpanAllocator.h:38
int32 GetMaxSize() const
Definition GrowOnlySpanAllocator.h:33
int32 GetSparselyAllocatedSize() const
Definition GrowOnlySpanAllocator.h:21
ENGINE_API void BeginDeferMerges()
Definition GrowOnlySpanAllocator.cpp:109
ENGINE_API void EndDeferMerges()
Definition GrowOnlySpanAllocator.cpp:115
Definition Array.h:670
@ Contains
Definition AutomationTest.h:160
U16 Index
Definition radfft.cpp:71