![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include <TripleBufferedData.h>
Public Member Functions | |
| TTripleBufferedData () | |
| DataType * | ExchangeProducerBuffer () |
| DataType * | ExchangeConsumerBuffer () |
A lock free paradigm for sharing data between threads.
Called a triple buffer because at any point in time, there may be 3 buffers available: 1 owned by the producing thread, 1 owned by the consuming thread, and 1 waiting in an atomic variable. The third storage location enables transfer of ownership such that if you have a copy of the data, you own it without worry of contention.
Producer thread:
Consumer thread:
|
inline |
|
inline |
Get an updated buffer for the consuming thread to read from.
The returned pointer may be null if the producer thread hasn't done an update since the last time this function was called.
The same capacity for a race condition exists with this functions return value as with ExchangeProducerBuffer().
Always refresh the same variable.
|
inline |
Get a new buffer for the producing thread to write to, while at the same time making the previous buffer available to the consumer.
This function will manufacture new instances of DataType, if it needs to. Thus, the returned pointer will never be null.
The DataType value is returned by shared pointer to simplify ownership semantics, particularly with respect to cleanup. It is important to not mistake that for exclusive ownership of the memory, and retain the return value of this function too long. For instance:
Instead, always reuse the same shared pointer, or dereference the returned shared pointer if you're not worried about copying the data.