Inquiry on Alignment Requirements

Patrick Rutkowski rutski89@gmail.com
Sun Aug 2 23:57:00 GMT 2009


I'm in the process of writing a memory allocator for a project of
mine; needless to say, GCC is one of the targeted compilers.

I find myself having to think about what memory alignment rules to
guarantee for pointers returned from my allocator. I know that some
subset of instructions on some architectures work much faster when
operating on properly aligned data. Furthermore, I know that other
such instructions flat out fail to work if operating on improperly
aligned data.

The question is: does GCC use such instructions? I don't want to
return poorly aligned data from my alloc() function and have GCC
try to use an aligned-only instruction it, resulting in things
exploding at runtime.

__alignof__ seems like it might be of some help:
http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Alignment.html#Alignment
But unfortunately it doesn't tell me what the _strictest_ alignment
rule is, which is what I need to know to write a generic memory
allocator.

Does GCC document or otherwise make known what minimum alignment it
expects on each platform?

I wish I could detect this automatically at build time; or during
./configure time (it's an autotools projects).

Thanks for reading,
-Patrick



More information about the Gcc-help mailing list