One of them is the alignment of data elements - their location in memory in relation to addresses that are multiples of four, eight or 16 bytes. According to Intel's 16-bit architecture, data alignment had little impact on performance, and its use was completely optional. According to IA-32, proper data alignment can be an important optimization, although its use is still optional, with very few exceptions, where proper alignment is mandatory. However, a 64-bit environment places more stringent requirements on data elements. Wrong objects cause program exceptions. For an element to be correctly aligned, it must meet the requirements of the 64-bit Intel architecture (discussed in the near future), as well as the requirements of the linker used to create the application.
The basic rule of data alignment is that the safest (and most widely supported) approach is based on Intel's meaning of "natural boundaries." These are those that occur when rounding the size of a data item to the next largest size of two, four, eight, or 16 bytes. For example, a 10-byte float should be aligned at a 16-byte address, while 64-bit integers should be aligned at an eight-byte address. Since this is a 64-bit architecture, the pointer sizes are eight bytes wide, so they should also be aligned along eight-byte boundaries.
It is recommended that all structures larger than 16 bytes be aligned at 16-byte boundaries. In general, for best performance, align the data as follows:
- Align 8-bit data to any address
- Align 16-bit data to be contained in a aligned four-byte word
- Align 32-bit data so its base address is a multiple of four
- Align 64-bit data so 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.
A structure or data array of 64 bytes or more in size must be aligned so that its base address is a multiple of 64. Sorting data while decreasing the size order is one heuristic to support natural alignment. While boundaries with 16 bytes (and cache lines) never intersect, natural alignment is not strictly necessary, although this is an easy way to ensure that general alignment recommendations are followed.
Correct alignment of data within structures can lead to data bloating (due to the filling necessary for proper placement of fields), therefore, when it is necessary and possible, it is useful to reorganize structures so that the fields requiring the widest alignment are the first in the structure. See the article "Preparing Code for the IA-64 Architecture (Code Cleanup)" for more information on resolving this problem.