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

Marc Mutz marc.mutz at kdab.com
Sun Jul 12 02:03:48 CEST 2015


On Saturday 11 July 2015 21:50:05 Smith Martin wrote:
> Suppose (as in the use case that started this thread) that your
> QList/QVector/QLinkedList will only have a small number of elements in it.
> Almost always less than 5. Never more than about 8. Does this change the
> analysis at all? In particular, does it minimize the performance
> differences?
> 
> And suppose the use case also assumes that you add all the elements to the
> container immediately and then you process the container sequentially
> immediately after that. So there is no inserting, no searching, and no
> other mallocs.

If you have only a very small number of elements, you should either be using a 
QVarLengthArray to avoid _any_ container-related heap allocations, or else a 
std::vector, because the overhead of the d-pointer is relatively-speaking a 
lot higher at small element counts.

And please stop chasing red herrings. It was _not_ the use of 
QList<ParsedSomething> in qdoc that originated this thread. Look at my Gerrit 
list of changes, merged and open. And my blog post is five years old.

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts



More information about the Development mailing list