D pointers

Lubos Lunak l.lunak at suse.cz
Tue Oct 4 15:07:51 BST 2005


On Tuesday 04 of October 2005 13:28, Dirk Mueller wrote:
> On Monday 03 October 2005 11:52, Stephan Kulow wrote:
> > One should note that you need to write a destructor and the assignment
> > operators anyway, as otherwise you have no guarantee that the compiler
> > will destruct the class even if you exchange the lib without recompiling
> > the apps later.
>
> Wrong. You have to add a dummy dtor if you try to be really sure that your
> dtor is called, but the assignment/copy ctr operators are not necessary.
>
> Furthermore as long as they're missing the compiler can do strength
> reduction which in some cases provides amazing speedup. My personal bet is
> that a lot of the QString speedups in Qt4 is actually just caused by the
> removal of the copy ctor on QChar.

 We're not talking QChar here. We're talking more complex classes, some of 
which could probably get higher benefits from reimplementing copies to become 
copy-on-write than just saving few CPU cycles this way, and anyway I'd say 
that vast majority of classes with d-pointers cannot be copied anyway 
(because of QObject).

 Moreover I think Stephan's point was that if you don't provide your own 
version, gcc will generate it itself, and you can't later change it, just 
like with e.g. dtors.

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak at suse.cz , l.lunak at kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/




More information about the kde-core-devel mailing list