D pointers

Thiago Macieira thiago at kde.org
Tue Oct 4 01:48:00 BST 2005


George Staikos wrote:
>  struct oldPixmapType { QPixmap a, b; };
>  mutable union {
>    struct {
>      QPixmap *icon, *miniIcon;
>    } pm;
>    char unused[sizeof(oldPixmapType)];
>  } aIconPixmap; // KDE4: remove me
>
>  Here we were even able to reuse the space so we didn't need to add to
> the d-pointer.

That's really ingenious. I hadn't thought of that!

However, even though that guarantees the proper sizeof, it doesn't 
guarantee __alignof and, hence, the necessary padding. 

You can solve that by adding one element to the union which has the same 
alignment requirements that QPixmap has. The hard part is figuring out 
which one that is.

So in general I don't think it's not a good idea to replace complex types 
with POD. The conclusion I come to is: if you're going to place a 
variable outside the private class, at least use POD types.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

3. Ac seo woruld wearð geborod, swá se Scieppend cwæð "Gewurde Unix" and 
wundor fremede and him "Unix" genemned, þæt is se rihtendgesamnung.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20051003/a1e7de4a/attachment.sig>


More information about the kde-core-devel mailing list