In this page:
http://qwt.sourceforge.net/class_qwt_plot_curve.html#afd13c94e23520dacbc37b4d0fd036a8b
The method
void QwtPlotCurve::setRawSamples()
just saves the addresses of the data in the QwtPlotCurve, which is exactly what I want for efficiency.
While:
void QwtPlotCurve::setSamples()
uses QVector, which is more convenient. But it’s only “explicitly shared”. What does that mean? does save the pointer just like the first one?
I need to add a point to the plot each 50 ms. Deep-copying of data isn’t the best solution!!! advice?
It’s juxtaposed against Qt’s concept of “implicit sharing”:
http://doc.qt.io/archives/qt-4.7/implicit-sharing.html
Even if you pass a QVector of data by value as a parameter in Qt, it will not copy the memory immediately. It will only make a copy if one of the vectors is changed.
I would have thought that the documentation saying “explicit sharing” in the setSamples case is just to draw attention to the fact that you’re passing in QVectors by reference instead of by value:
And I also would have thought they did this so that if you change the data in your vector (or free it), it will affect the data held onto by the plot curve. You’d not expect that if you thought the vectors were passed by value (you can’t tell if you’re just reading the callsite).
HOWEVER looking at the source code it appears that under the hood it’s just making an implicitly-shared copy anyway. In qwt_plot_curve.cpp we have:
We can see that QwtPointArrayData is declared in qwt_point_data.h like this:
The code for the constructor in qwt_point_data.cpp is just a simple assignment to
d_xandd_y. Which goes back to plain ol’ implicit sharing. So changes you make in the data you passed in will not be seen by the plot; you will pay for the copy being made at the time of such a modification.If they were just going to do this, then why they bothered passing in a const reference (instead of just by value) is a mystery to me. The only “sharing” going on here seems to be implicit, so I don’t know what the “explicitly shared” comment is supposed to mean.