Navigation
API > API/Runtime > API/Runtime/Core > API/Runtime/Core/Containers
References
| Module | Core |
| Header | /Engine/Source/Runtime/Core/Public/Containers/RingBuffer.h |
| Include | #include "Containers/RingBuffer.h" |
Syntax
template<typename T, typename AllocatorT>
class TRingBuffer
Remarks
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 threadsafe; 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.
Constructors
| Type | Name | Description | |
|---|---|---|---|
TRingBuffer () |
Construct Empty Queue with capacity 0. | ||
TRingBuffer
(
SizeType InitialCapacity |
Construct Empty Queue with the given initial requested capacity. | ||
TRingBuffer
(
std::initializer_list< ElementType > InitList |
Construct a Queue with initial state (from front to back) equal to the given list. | ||
TRingBuffer
(
TRingBuffer&& Other |
|||
TRingBuffer
(
const TRingBuffer& Other |
Destructors
| Type | Name | Description | |
|---|---|---|---|
~TRingBuffer () |
Functions
| Type | Name | Description | |
|---|---|---|---|
| IndexType | Add
(
const ElementType& Element |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | |
| IndexType | Add
(
ElementType&& Element |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | |
| ElementType & | Add_GetRef
(
const ElementType& Element |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | |
| ElementType & | Add_GetRef
(
ElementType&& Element |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | |
| IndexType | AddFront
(
const ElementType& Element |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | |
| IndexType | AddFront
(
ElementType&& Element |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | |
| ElementType & | AddFront_GetRef
(
ElementType&& Element |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | |
| ElementType & | AddFront_GetRef
(
const ElementType& Element |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | |
| IndexType | Add a new element before the front pointer of the RingBuffer, resizing if necessary. | ||
| ElementType & | Add a new element before the front pointer of the RingBuffer, resizing if necessary. | ||
| IndexType | Add a new element after the back pointer of the RingBuffer, resizing if necessary. | ||
| ElementType & | Add a new element after the back pointer of the RingBuffer, resizing if necessary. | ||
| TConstIterator | begin () |
Begin iterator for const ranged-for | |
| TIterator | begin () |
Begin iterator for ranged-for | |
| TArrayView< T > | Compact () |
Shift all elements so that the front pointer's location in memory is less than the back pointer's. | |
| 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. | |
| IndexType | Emplace
(
ArgsType&&... Args |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | |
| ElementType & | Emplace_GetRef
(
ArgsType&&... Args |
Add a new element after the back pointer of the RingBuffer, resizing if necessary. | |
| IndexType | EmplaceFront
(
ArgsType&&... Args |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | |
| ElementType & | EmplaceFront_GetRef
(
ArgsType&&... Args |
Add a new element before the front pointer of the RingBuffer, resizing if necessary. | |
| void | Empty the RingBuffer, destructing any elements and releasing the RingBuffer's storage. | ||
| TConstIterator | end () |
End iterator for const ranged-for | |
| TIterator | end () |
End iterator for ranged-for | |
| const ElementType & | First () |
Return a const reference to the element at the front pointer of the RingBuffer. | |
| ElementType & | First () |
Return a reference to the element at the front pointer of the RingBuffer. | |
| SIZE_T | Helper function to return the amount of memory allocated by this container. | ||
| ElementType & | GetAtIndexNoCheck
(
IndexType Index |
Unsafely return a writable reference to the value at the given Index. | |
| const ElementType & | GetAtIndexNoCheck
(
IndexType Index |
Unsafely return a const reference to the value at the given Index. | |
| bool | IsEmpty () |
Returns true if the RingBuffer is empty. | |
| 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. | |
| const ElementType & | Last () |
Return a const reference to the element at the back pointer of the RingBuffer. | |
| ElementType & | Last () |
Return a reference to the element at the back pointer of the RingBuffer. | |
| IndexType | Max () |
Current allocated Capacity, note this will always be a power of two, or the special case 0. | |
| void | MoveAppendRange
(
ElementType* OtherData, |
Append elements from a range onto the back pointer of the RingBuffer, resizing if necessary. | |
| IndexType | Num () |
Gets the number of elements in the RingBuffer. | |
| void | Pop the given number of arguments (default: 1) from the back pointer of the RingBuffer. | ||
| void | Pop the given number of elements (default: 1) from the front pointer of the RingBuffer. | ||
| void | PopFrontNoCheck
(
SizeType PopCount |
Unsafely pop the given number of arguments (default: 1) from the front pointer of the RingBuffer. | |
| ElementType | Pop one element from the front pointer of the RingBuffer and return the popped value. | ||
| void | PopNoCheck
(
SizeType PopCount |
Pop the given number of elements (default: 1) from the back pointer of the RingBuffer. | |
| ElementType | PopValue () |
Pop one element from the back pointer of the RingBuffer and return the popped value. | |
| SizeType | Remove
(
const ElementType& Item |
Removes as many instances of Item as there are in the array, maintaining order but not indices. | |
| SizeType | RemoveAll
(
PredicateType Predicate |
Removes as many instances of Item as there are in the array, maintaining order but not indices. | |
| void | Remove the value at the given index from the RingBuffer, and shift values ahead or behind it into its location to fill the hole. | ||
| void | Set the capacity to the maximum of the current capacity and the (next power of two greater than or equal to) the given capacity. | ||
| void | Reset () |
Empty the RingBuffer, destructing any elements in the RingBuffer but not releasing the RingBuffer's storage. | |
| 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. | |
| 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. | |
| 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. |
Operators
| Type | Name | Description | |
|---|---|---|---|
| bool | operator!=
(
const TRingBuffer< ElementType, OtherAllocator >& Other |
||
| const ElementType & | operator[]
(
IndexType Index |
Return a const reference to the value at the given Index. | |
| ElementType & | operator[]
(
IndexType Index |
Return a writable reference to the value at the given Index. | |
| TRingBuffer & | operator=
(
const TRingBuffer& Other |
||
| TRingBuffer & | operator=
(
TRingBuffer&& Other |
||
| bool | operator==
(
const TRingBuffer< ElementType, OtherAllocator >& Other |
Typedefs
| Name | Description |
|---|---|
| Allocator | The Allocator type being used |
| ElementType | Type of the Elements in the container. |
| IndexType | Type used to request values at a given index in the container. |
| SizeType | Type used to communicate size and capacity and counts |
| StorageModuloType | Type used for variables that are indexes into the underlying storage. |
| TConstIterator | |
| TIterator | Iterator type used for ranged-for traversal. |