Important: The information in this document is obsolete and should not be used for new development.
Data Alignment
The PowerPC runtime environment supports multiple data alignment modes. These alignments fall into two categories:
For example, the alignment of a
- the natural alignment, which is the alignment of a data type when allocated in memory or assigned a memory address
- the embedding alignment, which is the alignment of a data type within a composite data item
UInt16
variable may differ from that of aUInt16
data item embedded in a data structure.
Table 4-1 (page 4-3) shows the natural alignment of each data type, which is simply the size of the data type. This alignment is fixed.
- Note
- Data items passed as parameters in a routine call have their own special alignment rules. See "Routine Calling Conventions," beginning on page 4-11, for more information.
In data structures, you can specify an embedding alignment that varies depending on the alignment mode selected. Typically you can select the alignment mode using compiler options or pragmas. Table 4-2 shows the possible alignment modes.
Table 4-2 Embedded alignment modes Data type PowerPC 68K Packed Natural SInt8
UInt8
Boolean
1 1 1 1 SInt16
UInt16
2 2 1 2 SInt32
UInt32
4 2 1 4 float
4 2 1 4 double
4 or 8 2 1 8 Pointer 4 2 1 4 Composite 4 or 8 2 1 16 In all but the 68K alignment mode, the embedding alignment of a composite (for example, a data structure or an array) is determined by the largest embedding alignment of its members. The total size of a composite is rounded up to be a multiple of its embedded alignment.
In 68K alignment mode, the embedded alignment of a composite is always 2 bytes. The total size of the composite is rounded up to a multiple of two.
In PowerPC alignment mode, if the first embedded element in a data structure is type
double
, then the embedding alignment of all typedouble
members in the structure is 8. In such cases, the embedding alignment for the entire structure is also 8 bytes.Note that you may need to adjust embedded alignments if you are converting code from the classic 68K environment to the PowerPC (or CFM-68K) runtime environments. If you wish to enforce classic 68K alignment on your PowerPC code, you can often specify compiler pragmas or options to do so. Note, however, that the PowerPC processor is less efficient when accessing data that is not placed according to its natural alignment.
© Apple Computer, Inc.
11 MARCH 1997