[Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO
Marc Mutz
marc.mutz at kdab.com
Fri Jul 10 15:06:20 CEST 2015
On Friday 10 July 2015 13:35:34 Smith Martin wrote:
> >1) you put pressure on the memory allocator, by asking it to allocate on
> >the heap each individual C object you put in the list. Every single
> >allocation has a cost, plus the overhead you need for bookkeeping, plus
> >the costs of getting your memory fragmented, etc.;
>
> This pressure on the memory allocator, what is that? My memory doesn't get
> fragmented, because I only build lists; I never destroy them. But I do
> have to put each C somewhere, and if I use QVector<C>, doesn't it allocate
> a lot of them up front? I don't know how many i will need, but the number
> is usually 0, 1, or 2 -- the number of parameters in a function signature.
>
> >2) you make the compiler produce more inefficient code by introducing
> >the layer of indirection;
>
> But it will process the list one time only, from beginning to end.
>
> >3) you kill caching, as potentially every single access will result in a
> >cache miss (even in the common scenario of a simple forward iteration
> >over your list);
>
> Why? All the entries in the list are created at the same time (well, during
> the parsing of the function signature)
http://www.akkadia.org/drepper/cpumemory.pdf Sections 3 and 6. Please, read
it.
--
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