[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: D pointers
From:       Thiago Macieira <thiago () kde ! org>
Date:       2005-10-04 0:48:00
Message-ID: 200510032148.13916.thiago () kde ! org
[Download RAW message or body]


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.

[Attachment #3 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic