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.
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.
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).
stefan (12th May 2011), TheIndependentAquarius (22nd March 2016)
wow.. .i didn't know that Qt is so smart
Thanks!
Bookmarks