ReadWriteDoubleBuffer Class Template
Type-safe double-buffered container for messages of type T. More...
Declaration
Base class
| class | DoubleBuffer |
|
Abstract base class for type-erased message buffers. More... | |
Public Member Functions Index
template <typename T> | |
| void | reserve (size_t size) |
|
Pre-allocates memory for both buffers. More... | |
template <typename... Args> | |
| void | push (Args &&... args) |
|
Constructs and pushes a message to the write buffer. More... | |
template <typename T> | |
| auto | read () const noexcept -> std::span< const T > |
|
Returns a read-only view of messages in the read buffer. More... | |
template <typename T> | |
| void | swap () override |
|
Swaps read with write buffer. More... | |
template <typename T> | |
| void | clearReadBuffer () override |
|
Clears the read buffer. More... | |
template <typename T> | |
| void | clearWriteBuffer () override |
|
Clears the write buffer. More... | |
Private Member Attributes Index
template <typename T> | |
| ReadBuffer< T > | readBuffer_ |
template <typename T> | |
| WriteBuffer< T > | writeBuffer_ |
Description
Type-safe double-buffered container for messages of type T.
Implements a producer-consumer pattern where messages are written to one buffer while consumers read from another. This decouples message production from consumption and allows lock-free operation in single-threaded game loops.
- Template Parameters
-
T The message type stored in this buffer. Must be movable.
Definition at line 34 of file ReadWriteDoubleBuffer.ixx.
Public Member Functions
clearReadBuffer()
| inline virtual |
Clears the read buffer.
Definition at line 93 of file ReadWriteDoubleBuffer.ixx.
Reference helios::engine::core::container::buffer::ReadBuffer< T >::clear.
clearWriteBuffer()
| inline virtual |
Clears the write buffer.
Definition at line 100 of file ReadWriteDoubleBuffer.ixx.
Reference helios::engine::core::container::buffer::WriteBuffer< T >::clear.
push()
| inline |
Constructs and pushes a message to the write buffer.
- Template Parameters
-
Args Constructor argument types for T.
- Parameters
-
args Arguments forwarded to T's constructor.
Definition at line 67 of file ReadWriteDoubleBuffer.ixx.
References helios::engine::core::container::buffer::WriteBuffer< T >::push and helios::registerComponents.
read()
| inline noexcept |
Returns a read-only view of messages in the read buffer.
- Returns
A span over all messages written in the previous frame.
Definition at line 76 of file ReadWriteDoubleBuffer.ixx.
Reference helios::engine::core::container::buffer::ReadBuffer< T >::read.
reserve()
| inline |
Pre-allocates memory for both buffers.
- Parameters
-
size The number of messages to reserve capacity for.
Definition at line 54 of file ReadWriteDoubleBuffer.ixx.
References helios::engine::core::container::buffer::ReadBuffer< T >::reserve and helios::engine::core::container::buffer::WriteBuffer< T >::reserve.
swap()
| inline virtual |
Swaps read with write buffer.
Swaps the read- with the write-buffer. The write buffer is empty after this operation, while the read buffer contains the contents of the write buffer.
Definition at line 86 of file ReadWriteDoubleBuffer.ixx.
Reference helios::engine::core::container::buffer::ReadBuffer< T >::clear.
Private Member Attributes
readBuffer_
|
Buffer containing messages available for reading.
Definition at line 39 of file ReadWriteDoubleBuffer.ixx.
writeBuffer_
|
Buffer where new messages are pushed.
Definition at line 44 of file ReadWriteDoubleBuffer.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.