Memory alignment on i386

CamiloAlejo at netscape.net CamiloAlejo at netscape.net
Fri Aug 27 19:26:16 UTC 2004


Jay Monkman <jtm-list-rtems at smoothsmoothie.com> wrote:

>What exactly do you want aligned? You don't really mean you want
>_every_ variable 32-bit aligned, do you?

Well, it is almost what I want. I'm using some tricks for accessing structure members, and the tricks are useless if the structure members are not 32-bit aligned.

Under cygwin i have that

struct unpacked_type {
    char    var1;
    char    var2;
};

has a size of 8, and

struct packed_type {
    char     var1;
    char     var2;
} __attribute__((packed));

has a size of 2, but under RTEMS I found both structures having size of 2.

What I really need is havig structure members 32-bit aligned. Having also every single variable 32-bit aligned could be a performance improvment, but is not that important now.

I checked compiler specs, and I found nothing indicating the structures are being packed.

>
>You can specify the alignment of particular variables using gcc's
>__attribute__ keyword.
>   int i        __attribute__(( aligned(4) ));
>   struct foo   __attribute__(( aligned(4) ));
>
>You can pass -malign-double on gcc's command line. Here's what the
>documention says about it:
>     Control whether GCC aligns `double', `long double', and `long
>     long' variables on a two word boundary or a one word boundary.
>     Aligning `double' variables on a two word boundary will produce
>     code that runs somewhat faster on a `Pentium' at the expense of
>     more memory.
>
>     *Warning:* if you use the `-malign-double' switch, structures
>     containing the above types will be aligned differently than the
>     published application binary interface specifications for the 386
>     and will not be binary compatible with structures in code
>     compiled without that switch.
>
>-malign-double is x86 specific.
>
>

__________________________________________________________________
Switch to Netscape Internet Service.
As low as $9.95 a month -- Sign up today at http://isp.netscape.com/register

Netscape. Just the Net You Need.

New! Netscape Toolbar for Internet Explorer
Search from anywhere on the Web and block those annoying pop-ups.
Download now at http://channels.netscape.com/ns/search/install.jsp



More information about the users mailing list