PDA

View Full Version : QVector::data() and implicit sharing



abernat
7th July 2009, 17:13
I have a QVector and need to call the data() function to obtain a value I can use as an argument for a function from a 3rd party library. Does calling data() increase the reference count to the QVector, and if so, is there a way to manually dereference when the 3rd party function has finished executing and I'm done with the pointer?

wysota
7th July 2009, 17:52
No, it doesn't. Why would it? You're not making a copy of the vector, only accessing data it holds. Note that if QVector holds items that are reference counted themselves, changing them (through data) might result in changes in reference counts of those items.

Note that calling data() detaches the vector (it's a non-const method), so the reference count might decrease!

abernat
7th July 2009, 18:34
Thanks, I was a bit fuzzy about how implicit sharing worked in Qt, but your explanation cleared it up for me.