[Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO
Giuseppe D'Angelo
giuseppe.dangelo at kdab.com
Fri Jul 10 13:26:47 CEST 2015
Il 10/07/2015 13:21, Smith Martin ha scritto:
> But I'm still not clear on one point. If I use QList<C>, and it is implemented as QList<C*> because my C is not a "good" C, why is this inefficent if the only copy of each C is the one that gets allocated on the heap? I just create the list to store things. It won't ever be moved. I will just process the list when it's time comes.
>
> Why is that inefficient?
Because
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.;
2) you make the compiler produce more inefficient code by introducing
the layer of indirection;
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);
and so on.
Cheers,
--
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Software Engineer
KDAB (UK) Ltd., a KDAB Group company | Tel: UK +44-1625-809908
KDAB - The Qt Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4048 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/development/attachments/20150710/16a026f9/attachment.bin>
More information about the Development
mailing list