After some readings, I understand that the compiler has done padding for structures or classes, so that each member can be accessed at its natural aligned border. So, under what circumstances is it necessary for encoders to do clear alignment to achieve better performance? My question arises here:
Intel 64 and IA-32 Archiving Optimization Reference Guide:
For best performance, align data as follows: Align 8-bit data at any address. Align 16-bit data to be contained within an aligned 4-byte word. Align 32-bit data so that its base address is a multiple of four. Align 64-bit data so that its base address is a multiple of eight. Align 80-bit data so that its base address is a multiple of sixteen. Align 128-bit data so that its base address is a multiple of sixteen.
So, suppose I have a structure:
struct A { int a; int b; int c; }
By creating an array of type A, even if I do nothing, it will be aligned correctly. Then what's the point of following the manual and making alignment stronger?
Is it because of line splitting in cache? Assuming the cache line is 64 bytes. At the 6th access of the object in the byte array, it starts from 61 to 72, which slows down the program
BTW, is there a macro in the standard library that tells me the alignment requirement based on the current machine, returning the value std :: size_t?
source share