UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CircularBuffer.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"
7#include "Containers/Array.h"
9
17template<typename InElementType> class TCircularBuffer
18{
19public:
21
28 {
30 checkSlow(Capacity <= 0xffffffffU);
31
32 Elements.AddZeroed(FMath::RoundUpToPowerOfTwo(Capacity));
33 IndexMask = Elements.Num() - 1;
34 }
35
43 {
44 checkSlow(Capacity <= 0xffffffffU);
45
46 Elements.Init(InitialValue, FMath::RoundUpToPowerOfTwo(Capacity));
47 IndexMask = Elements.Num() - 1;
48 }
49
50public:
51
58 {
59 return Elements[Index & IndexMask];
60 }
61
68 {
69 return Elements[Index & IndexMask];
70 }
71
72public:
73
80 {
81 return Elements.Num();
82 }
83
91 {
92 return ((CurrentIndex + 1) & IndexMask);
93 }
94
102 {
103 return ((CurrentIndex - 1) & IndexMask);
104 }
105
106private:
107
109 uint32 IndexMask;
110
112 TArray<ElementType> Elements;
113};
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Init(const ElementType &Element, SizeType Number)
Definition Array.h:3043
SizeType AddZeroed()
Definition Array.h:2755
Definition CircularBuffer.h:18
InElementType ElementType
Definition CircularBuffer.h:20
UE_FORCEINLINE_HINT uint32 GetPreviousIndex(uint32 CurrentIndex) const
Definition CircularBuffer.h:101
UE_FORCEINLINE_HINT const ElementType & operator[](uint32 Index) const
Definition CircularBuffer.h:67
UE_FORCEINLINE_HINT ElementType & operator[](uint32 Index)
Definition CircularBuffer.h:57
UE_FORCEINLINE_HINT uint32 Capacity() const
Definition CircularBuffer.h:79
UE_FORCEINLINE_HINT uint32 GetNextIndex(uint32 CurrentIndex) const
Definition CircularBuffer.h:90
TCircularBuffer(uint32 Capacity, const ElementType &InitialValue)
Definition CircularBuffer.h:42
TCircularBuffer(uint32 Capacity)
Definition CircularBuffer.h:27
U16 Index
Definition radfft.cpp:71