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 | [email protected] | Software Engineer
KDAB (UK) Ltd., a KDAB Group company | Tel: UK +44-1625-809908
KDAB - The Qt Experts

Attachment: smime.p7s
Description: Firma crittografica S/MIME

_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to