QCustomPlot Discussion and Comments

faster setData() functionReturn to overview

I wrote setData function like that:

QVector<double> x(100), y(100);
customPlot->graph(0)->setData(x, y);

first question: Is QCPGraph::setData ( QCPDataMap * data, bool copy = false ) function faster than QCPGraph::QCPGraph ( QCPAxis * keyAxis, QCPAxis * valueAxis ) if copy is false ?

second question: how can I use my vectors with QCPGraph::setData ( QCPDataMap * data, bool copy = false )

thank you.

With such a small amount of points, never mind the time needed to copy the data. Copying the data is in almost all cases much faster than the actual replot time needed for drawing the lines and points. A wise man once said "premature optimization is the root of all evil".

If you really want to know: calling QCPGraph::setData ( QCPDataMap * data, bool copy = false ) is always just a copy of one pointer, so 4 or 8 bytes depending on the system bitness. However the memory the pointer points to is then owned by the graph, which requires extra care when still storing the pointer somewhere in your application.

I recommend using setData(vector, vector) or addData, unless you have benchmarked that the copy time really matters.

Ok. Thank you for your answer