Background data production¶
Produce large or expensive buffers off the UI thread and hand over only completed buffers.
Simplest handoff¶
LineCurve::postData() can be called from any thread. It moves
the buffer into a queued call that runs setDataF() on the
curve's thread:
void Producer::publish(QAccelPlot::LineCurve* curve)
{
auto points = buildInterleavedPoints();
const auto count = static_cast<int>(points.size() / 2);
curve->postData(std::move(points), count);
}
One-batch handoff¶
For high-rate updates, keep one pending batch. The worker prepares the next batch and waits until the UI thread has consumed the previous one. Once per frame, the UI thread moves the pending batch into the curve. This bounds memory and skips frames that could never be displayed.
DataBatch batch;
if (worker.tryConsume(batch)) {
curve->setDataF(std::move(batch.points), batch.pointCount);
}
If the worker already knows the extents, add them to the batch and pass them
as DataBounds to skip the
range scan on the UI
thread.
The performance showcase also builds the vertex cache on the worker. Adopt that only after profiling the simpler handoff.
Complete source: examples/showcases/performance