Alignment of data types
The memory layout of a data type is determined by the alignment. Further information on the alignment can be found in the “Alignment” section in the documentation entitled “PLC”.
With the default alignment of 8 bytes it can be ensured that the access to data types functions optimally in terms of runtime and access on different platforms. Deviation from this should only take place in exceptional cases.
The TwinCAT 3 type system marks data types in color.
- Yellow if the length of the data type is not a multiple of the largest internal field (max. 8 bytes). As a result, the alignment no longer obeys the rules in the case of an array of such a data type.
- Red if the alignment within the data type no longer obeys the rules.
The TMC editor offers the possibility to specify the memory layout of a data type for a selected alignment.
Alternatively, the layout can be manually specified using offsets.
If the size of a data type that is used in another data type is changed, then this data type must also be adjusted. The TMC editor offers an appropriate recursive function for this at the data type overview level.