[Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO

Thiago Macieira thiago.macieira at intel.com
Fri Jul 10 22:53:33 CEST 2015


On Friday 10 July 2015 13:45:34 Randall O'Reilly wrote:
> I’m surprised nobody has mentioned that, because of the private data nature
> of most Qt classes, they are a) already allocating the private data object
> on the heap all the time and incurring all that overhead and memory
> allocation badness, and b) are essentially a pointer to an object already —

What you're describing has been mentioned. It's the whole point of the 
discussion.

But it's not due to the private nature of the classes. Any dynamic storage 
class has to do that anyway.

std::vector<T>, std::string, QVector<T> and QString have the same number of 
indirections to the data (exactly 1).

std::list<T> and QLinkedList<T> also have the exact same number: N, to access 
index N.

The difference is QList: it either has 1 indirection,  if operating like 
QVector, or 2 if operating as a pointer array. So other than the first element, 
QList has equal or better performance than QLinkedList and std::list.

So QList is a superior list, superior to std::list if you don't strictly 
require O(1) insertions and deletions. The point is that a list model is less 
efficient than a vector/array model.

Maybe we didn't realise that in 1999 when Qt 2 was created, which added QList 
as an API for everything, a policy that got inherited by Qt 3's QValueList and 
then Qt 4 & 5's QList.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list