QVector as function argument
http://www.daniweb.com/software-deve...threads/112482
Does this also apply on Qvector?
I pass large arrays (100000x100 double) many times (around 30000 times) and cant see the difference (in execution time) between
Code:
f(QVector<QVector<double>>& _array);
and
Code:
f(QVector<QVector<double>> _array);
Thanks for your time, Stefan
Re: QVector as function argument
QVector is implicit shared - so as long as you don't modify the QVector there is no deep copy if you pass by value, you can read more about implicit sharing here.
Re: QVector as function argument
Quote:
Originally Posted by
Zlatomir
QVector is implicit shared - so as long as you don't modify the QVector there is no deep copy if you pass by value, you can read more about implicit sharing
here.
Thank you for quick answer!
So if I dont modify _array in function f - then array is passed by reference? Compiler decides that?
Re: QVector as function argument
No, not the compiler, the class QVector is implemented in such a way that when you copy the QVector it doesn't copy all the data - it actually copy only a pointer and in increment the reference count variable (so that it can know if anybody else has access/share the same data) - this is implicit sharing (reference counting).
And when you try to modify a QVector - it checks the reference count and if the object you try to modify is not the only one who shares the data it will copy the data and modify it's own copy (this is copy on write).
Re: QVector as function argument
wow.. .i didn't know that Qt is so smart :)
Thanks!