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 |
|||
TRingBuffer
(
uint32 BufferDataSize |
ConstructorTRingBuffer implementation |
Destructors
| Type | Name | Description | |
|---|---|---|---|
~TRingBuffer () |
Default Destructor | ||
~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
(
const 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. | |
| 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. | ||
| TIterator | begin () |
Begin iterator for ranged-for | |
| TConstIterator | begin () |
Begin iterator for const ranged-for | |
| DataType & | Bottom () |
Gets the first data word in the FIFO (i.e. oldest). | |
| const DataType & | Bottom () |
Gets the first data word in the FIFO (i.e. oldest). | |
| uint32 | BottomIndex () |
Gets the buffer index that the first data word is stored in. | |
| 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. | |
| uint32 | Take the next set of data words from the FIFO buffer. | ||
| bool | Take the next data word from the FIFO buffer. | ||
| 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 () |
Clears memory and indexes | |
| void | Empty the RingBuffer, destructing any elements and releasing the RingBuffer's storage. | ||
| TIterator | end () |
End iterator for ranged-for | |
| TConstIterator | end () |
End iterator for const ranged-for | |
| void | Pushes a data word to the end of the FIFO. WILL OVERWRITE OLDEST if full. | ||
| void | Pushes a buffer of data words to the end of the FIFO. WILL OVERWRITE OLDEST if full. | ||
| ElementType & | First () |
Return a reference to the element at the front pointer of the RingBuffer. | |
| const ElementType & | First () |
Return a const 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. | ||
| const ElementType & | GetAtIndexNoCheck
(
IndexType Index |
Unsafely return a const reference to the value at the given Index. | |
| ElementType & | GetAtIndexNoCheck
(
IndexType Index |
Unsafely return a writable reference to the value at the given Index. | |
| void | GetShaHash
(
FSHAHash& OutHash |
Get the SHA1 hash for the data currently in the FIFO | |
| 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. | |
| uint32 | NextIndex () |
Gets the buffer index that the next enqueued word will get stored in. | |
| IndexType | Num () |
Gets the number of elements in the RingBuffer. | |
| uint32 | Get the next set of data words from the FIFO buffer without removing them. | ||
| bool | Get the next data word from the FIFO buffer without removing it. | ||
| 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. | |
| uint32 | RingDataSize () |
Gets the size of the data buffer. | |
| uint32 | Gets the number of words currently in the FIFO. | ||
| int32 | SerialCompare
(
const DataType* SerialBuffer, |
Compare the memory in the FIFO to the memory in the given buffer | |
| void | Serializes the internal buffer into the given buffer | ||
| 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. | |
| const DataType & | Top () |
Gets the last data word in the FIFO (i.e. most recently pushed). | |
| DataType & | Top () |
Gets the last data word in the FIFO (i.e. most recently pushed). | |
| uint32 | TopIndex () |
Gets the buffer index that the last data word is stored in. | |
| uint64 | Gets the total number of words that have been pushed through this buffer since clearing | ||
| 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 |
||
| ElementType & | operator[]
(
IndexType Index |
Return a writable reference to the value at the given Index. | |
| const ElementType & | operator[]
(
IndexType Index |
Return a const reference to the value at the given Index. | |
| const DataType & | operator[]
(
const int32& Index |
Square bracket operators for accessing data in the buffer by FIFO index. | |
| DataType & | operator[]
(
const int32& 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. |