TTripleBufferedData::ExchangeProducerBuffer

Get a new buffer for the producing thread to write to, while at the same time making the previous buffer available to the consumer.

Windows
MacOS
Linux

References

Module

ChaosSolvers

Header

/Engine/Source/Runtime/Experimental/ChaosSolvers/Public/Framework/TripleBufferedData.h

Include

#include "Framework/TripleBufferedData.h"

Syntax

DataType * ExchangeProducerBuffer()

Remarks

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: TTripleBufferedDataIntBuffer;...int*MyCopy=IntBuffer.ExchangeProducerBuffer();(*MyCopy)=1;//OkIntBuffer.ExchangeProducerBuffer();//Memholding"1"nowavailabletoconsumerthread.(*MyCopy)=2;//Racecondition!

Instead, always reuse the same shared pointer, or dereference the returned shared pointer if you're not worried about copying the data. TTripleBufferedDataIntBuffer;...int*MyCopy=IntBuffer.ExchangeProducerBuffer();(*MyCopy)=1;//OkMyCopy=IntBuffer.ExchangeProducerBuffer();//Memholding"1"nowavailabletoconsumerthread.(*MyCopy)=2;//Ok

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss