alignment on stack-allocated arrays/structs

Don nospam at nospam.com
Wed Nov 18 08:03:19 PST 2009


Trass3r wrote:
> Don schrieb:
>> http://d.puremagic.com/issues/show_bug.cgi?id=2278
> 
> Isn't this a distinct problem or am I wrong? This is not only about 
> 8-byte boundaries.

Well, sort of.
It's impossible to align stack-allocated structs with any alignment 
greater than the alignment of the stack itself (which is 4 bytes). 
Anything larger than that and you HAVE to use the heap or alloca().

Since D2.007, static items use align(16); before that, they were also 
limited to align(4).

Nothing on x86 benefits from more than 16 byte alignment, AFAIK, and 
it's never mandatory to use more than 8 byte alignment. I don't know so 
much about the recent GPUs, though -- do they really require 16 byte 
alignment or more?




More information about the Digitalmars-d mailing list