Do I understand right that it does not make real sense to have
and that I can stick just to:
due to implicit sharing?
Honestly, using STL, I would never do like this and would have
My question is about performance. I understand that it’s different ways of storing objects.
No, those have different behaviour.
QVector<QVariantHash> is still copy-on-write, so copies of the vector only share elements up to the first modification, whereas so long as you leave the pointers alone, the
QVariantHashs pointed-to by the elements of
QVector<QSharedPointer<QVariantHash>> will still be the same objects.
As an aside, I would avoid relying on implicit sharing, because it is really easy to fall into undefined behaviour, with pointers or references being invalidated from underneath you.
I would also caution against overuse of shared pointers. Almost always you can have one thing with unique ownership which hands out references.
Answered By – Caleth
Answer Checked By – Willingham (BugsFixing Volunteer)