Navigation
API > API/Runtime > API/Runtime/Core
RingBuffer - an array with a Front and Back pointer and with implicit wraparound to the beginning of the array when reaching the end of the array when iterating from Front to Back Useful for providing O(1) push/pop at the end of the array (for Queue or Stack) while still having high cache coherency during iteration. Not thread-safe; caller must ensure there is no simultaneous access from multiple threads.
Implementation Details: Relies on unsigned arithmetics and ever-increasing Front and Back indices to avoid having to store an extra element or maintain explicit empty state. Capacity will always be rounded up to the next power of two, to provide rapid masking of the index.
| Name | TRingBuffer |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Containers/RingBuffer.h |
| Include Path | #include "Containers/RingBuffer.h" |
Syntax
template<typename T, typename AllocatorT>
class TRingBuffer
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TRingBuffer
(
TRingBuffer&& Other |
Containers/RingBuffer.h | ||
TRingBuffer () |
Construct Empty Queue with capacity 0. | Containers/RingBuffer.h | |
TRingBuffer
(
SizeType InitialCapacity |
Construct Empty Queue with the given initial requested capacity. | Containers/RingBuffer.h | |
TRingBuffer
(
std::initializer_list< ElementType > InitList |
Construct a Queue with initial state (from front to back) equal to the given list. | Containers/RingBuffer.h | |
TRingBuffer
(
const TRingBuffer& Other |
Containers/RingBuffer.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~TRingBuffer() |
Containers/RingBuffer.h |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| Allocator | AllocatorT | The Allocator type being used | Containers/RingBuffer.h |
| ElementAllocatorType | std::conditional_t< Allocator::NeedsElementType, typename Allocator::template ForElementType< ElementType >, typename Allocator::ForAnyElementType > | Containers/RingBuffer.h | |
| ElementType | T | Type of the Elements in the container. | Containers/RingBuffer.h |
| IndexType | std::make_signed_t< typename Allocator::SizeType > | Type used to request values at a given index in the container. | Containers/RingBuffer.h |
| SizeType | std::make_unsigned_t< typename Allocator::SizeType > | Type used to communicate size and capacity and counts | Containers/RingBuffer.h |
| StorageModuloType | std::make_unsigned_t< typename Allocator::SizeType > | Type used for variables that are indexes into the underlying storage. | Containers/RingBuffer.h |
| TConstIterator | TRingBufferIterator< const TRingBuffer, const ElementType, typename Allocator::SizeType > | Containers/RingBuffer.h | |
| TIterator | TRingBufferIterator< TRingBuffer, ElementType, typename Allocator::SizeType > | Iterator type used for ranged-for traversal. | Containers/RingBuffer.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| AfterBack | StorageModuloType | Pointer to the first location after the back pointer of the RingBuffer; when the RingBuffer is non-empty, one element before this index is the back of the RingBuffer AfterBack is in StorageModulo space. | Containers/RingBuffer.h | |
| AllocatorInstance | ElementAllocatorType | The underlying storage of the RingBuffer is in the c-style array provided by this AllocatorInstance.GetAllocation(). | Containers/RingBuffer.h | |
| Front | StorageModuloType | Front pointer of the RingBuffer; it points to the first element in the iteration of the RingBuffer, unless the RingBuffer is empty, in which case it can point to any value in the underlying storage. | Containers/RingBuffer.h | |
| IndexMask | StorageModuloType | A bitmask used to convert from StorageModulo space into an index into Storage. | Containers/RingBuffer.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
IndexType Add
(
const ElementType& Element |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
IndexType Add
(
ElementType&& Element |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
ElementType & Add_GetRef
(
const ElementType& Element |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
ElementType & Add_GetRef
(
ElementType&& Element |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
IndexType AddFront
(
const ElementType& Element |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
IndexType AddFront
(
ElementType&& Element |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
ElementType & AddFront_GetRef
(
ElementType&& Element |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
ElementType & AddFront_GetRef
(
const ElementType& Element |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
IndexType AddFrontUninitialized () |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
ElementType & AddFrontUninitialized_GetRef () |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
IndexType AddUninitialized () |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
ElementType & AddUninitialized_GetRef () |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
TConstIterator begin () |
Begin iterator for const ranged-for | Containers/RingBuffer.h | |
TIterator begin () |
Begin iterator for ranged-for | Containers/RingBuffer.h | |
TArrayView< T > Compact () |
Shift all elements so that the front pointer's location in memory is less than the back pointer's. | Containers/RingBuffer.h | |
IndexType ConvertPointerToIndex
(
const ElementType* Ptr |
Given a pointer to an Element anywhere in memory, return the index of the element in the RingBuffer, or INDEX_NONE if it is not present. | Containers/RingBuffer.h | |
IndexType Emplace
(
ArgsType&&... Args |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
ElementType & Emplace_GetRef
(
ArgsType&&... Args |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
IndexType EmplaceFront
(
ArgsType&&... Args |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
ElementType & EmplaceFront_GetRef
(
ArgsType&&... Args |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
void Empty
(
SizeType Capacity |
Empty the RingBuffer, destructing any elements and releasing the RingBuffer's storage. | Containers/RingBuffer.h | |
TConstIterator end () |
End iterator for const ranged-for | Containers/RingBuffer.h | |
TIterator end () |
End iterator for ranged-for | Containers/RingBuffer.h | |
ElementType & First () |
Return a reference to the element at the front pointer of the RingBuffer. | Containers/RingBuffer.h | |
const ElementType & First () |
Return a const reference to the element at the front pointer of the RingBuffer. | Containers/RingBuffer.h | |
SIZE_T GetAllocatedSize () |
Helper function to return the amount of memory allocated by this container. | Containers/RingBuffer.h | |
const ElementType & GetAtIndexNoCheck
(
IndexType Index |
Unsafely return a const reference to the value at the given Index. | Containers/RingBuffer.h | |
ElementType & GetAtIndexNoCheck
(
IndexType Index |
Unsafely return a writable reference to the value at the given Index. | Containers/RingBuffer.h | |
bool IsEmpty() |
Returns true if the RingBuffer is empty. | Containers/RingBuffer.h | |
bool IsValidIndex
(
IndexType Index |
Tests if index is valid, i.e. greater than or equal to zero, and less than the number of elements in the array. | Containers/RingBuffer.h | |
ElementType & Last () |
Return a reference to the element at the back pointer of the RingBuffer. | Containers/RingBuffer.h | |
const ElementType & Last () |
Return a const reference to the element at the back pointer of the RingBuffer. | Containers/RingBuffer.h | |
IndexType Max() |
Current allocated Capacity, note this will always be a power of two, or the special case 0. | Containers/RingBuffer.h | |
void MoveAppendRange
(
ElementType* OtherData, |
Append elements from a range onto the back pointer of the RingBuffer, resizing if necessary. | Containers/RingBuffer.h | |
IndexType Num() |
Gets the number of elements in the RingBuffer. | Containers/RingBuffer.h | |
void Pop
(
SizeType PopCount |
Pop the given number of arguments (default: 1) from the back pointer of the RingBuffer. | Containers/RingBuffer.h | |
void PopFront
(
SizeType PopCount |
Pop the given number of elements (default: 1) from the front pointer of the RingBuffer. | Containers/RingBuffer.h | |
void PopFrontNoCheck
(
SizeType PopCount |
Unsafely pop the given number of arguments (default: 1) from the front pointer of the RingBuffer. | Containers/RingBuffer.h | |
ElementType PopFrontValue () |
Pop one element from the front pointer of the RingBuffer and return the popped value. | Containers/RingBuffer.h | |
void PopNoCheck
(
SizeType PopCount |
Pop the given number of elements (default: 1) from the back pointer of the RingBuffer. | Containers/RingBuffer.h | |
ElementType PopValue () |
Pop one element from the back pointer of the RingBuffer and return the popped value. | Containers/RingBuffer.h | |
SizeType Remove
(
const ElementType& Item |
Removes as many instances of Item as there are in the array, maintaining order but not indices. | Containers/RingBuffer.h | |
SizeType RemoveAll
(
PredicateType Predicate |
Removes all items for which a given predicate applies, maintaining order but not indices. | Containers/RingBuffer.h | |
void RemoveAt
(
IndexType Index |
Remove the value at the given index from the RingBuffer, and shift values ahead or behind it into its location to fill the hole. | Containers/RingBuffer.h | |
void Reserve
(
SizeType RequiredCapacity |
Set the capacity to the maximum of the current capacity and the (next power of two greater than or equal to) the given capacity. | Containers/RingBuffer.h | |
void Reset() |
Empty the RingBuffer, destructing any elements in the RingBuffer but not releasing the RingBuffer's storage. | Containers/RingBuffer.h | |
void ShiftIndexToBack
(
IndexType Index |
Move the value at the given index into the back pointer of the RingBuffer, and shift all elements behind of it up by one to make room for it. | Containers/RingBuffer.h | |
void ShiftIndexToFront
(
IndexType Index |
Move the value at the given index into the front pointer of the RingBuffer, and shift all elements ahead of it down by one to make room for it. | Containers/RingBuffer.h | |
void Trim() |
Set the capacity to the minimum power of two (or 0) greater than or equal to the current number of elements in the RingBuffer. | Containers/RingBuffer.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static bool NeedsDestructElements() |
Containers/RingBuffer.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
bool operator!=
(
const TRingBuffer< ElementType, OtherAllocator >& Other |
Containers/RingBuffer.h | ||
ElementType & operator[]
(
IndexType Index |
Return a writable reference to the value at the given Index. | Containers/RingBuffer.h | |
const ElementType & operator[]
(
IndexType Index |
Return a const reference to the value at the given Index. | Containers/RingBuffer.h | |
TRingBuffer & operator=
(
TRingBuffer&& Other |
Containers/RingBuffer.h | ||
TRingBuffer & operator=
(
const TRingBuffer& Other |
Containers/RingBuffer.h | ||
bool operator==
(
const TRingBuffer< ElementType, OtherAllocator >& Other |
Containers/RingBuffer.h |