Original Post
I posted about alignment a while ago but more about why its needed and its relevance with SSE instructions etc. I have a few more questions about alignment that I thought would be better in a new post. 1) Assuming that it is best to try and align all your data, what alignment do you shoot for? If you are aligning a variable that will be used in SSE code for example, you would want 16 byte alignment. But what do you go for the rest of the time? I.e. if you have a structure you wanted to pad so it was aligned...what size padding? Is there an easy way (or reference) to work it out for your specific hardware? Do you target cache line size? Which cache would you aim for etc? 2) I presume that you only shoot for alignment in release builds as in debug, the debug CRT will add debug headers and before and after blocks for buffer overrun detection. Therefore, this will upset alignment but is it ok not to worry about it in this situation? If you have any code that requires alignment, would you just guard that code with pre-processor #ifdefs and check for _DEBUG? 3) How much should you use the compiler to force alignment? For example VC++ provides __declspec(align(#)) where you can specify a power of two value for alignment at variable declaration.