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:
void QwtPlotCurve::setSamples(
const QVector< double > &xData,
const QVector< double > &yData
)
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:
/*!
\brief Initialize data with x- and y-arrays (explicitly shared)
\param xData x data
\param yData y data
\sa QwtPointArrayData
*/
void QwtPlotCurve::setSamples( const QVector<double> &xData,
const QVector<double> &yData )
{
setData( new QwtPointArrayData( xData, yData ) );
}
We can see that QwtPointArrayData is declared in qwt_point_data.h like this:
class QWT_EXPORT QwtPointArrayData: public QwtSeriesData<QPointF>
{
public:
QwtPointArrayData( const QVector<double> &x, const QVector<double> &y );
QwtPointArrayData( const double *x, const double *y, size_t size );
virtual QRectF boundingRect() const;
virtual size_t size() const;
virtual QPointF sample( size_t i ) const;
const QVector<double> &xData() const;
const QVector<double> &yData() const;
private:
QVector<double> d_x;
QVector<double> d_y;
};
The code for the constructor in qwt_point_data.cpp is just a simple assignment to d_x
and d_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.