D pointers

Thiago Macieira thiago at kde.org
Tue Oct 4 05:51:25 BST 2005


George Staikos wrote:
>  I seem to recall that we went through this and determined that
> alignment was going to be correct so we didn't need to do anything
> different.  Well maybe until we run on 128-bit systems?
>
>  Actually don't the pointers guarantee we are aligned properly anyway?

I know you and I trust you and the core guys hacking on KApplication to 
take the necessary precautions.

But as a general policy on BIC, I'd say "don't replace complex types with 
other types".

There are some types that have more strict alignment requirements than 
pointers. On x86, the most strict alignment is 4 bytes, but IA-64 
requires pointers to be aligned on 8-byte boundary, whereas anything 
larger than 8 bytes must be aligned on a 16-byte boundary. x86-64 has 
similar restrictions.

For instance, the following two structs don't have the same sizeof on 
x86-64:

struct Type1 {
  char *ptr;
  long double data;
};

struct Type2 {
  char *ptr;
  union {
    struct { void* data; } pm;
    char padding[sizeof(long double)];
  } un;
};

The results:
Type 1:  32
Type 2:  24
(courtesy of Sourceforge.net's compile farm)

As a comparison, this is my x86:
Type 1:  16
Type 2:  16

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

4. And æfter se scieppend ingelogode, he wrát "cenn", ac eala! se 
rihtendgesamnung andswarode "cenn: ne wát hú cennan 'eall'. Ástynt."
-------------- 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/20051004/6a15977d/attachment.sig>


More information about the kde-core-devel mailing list