4.37 Performance penalty associated with marking whole structures as packed

Reading from and writing to whole structures qualified with __packed requires unaligned accesses and can therefore incur a performance penalty.

When optimizing a struct that is packed, the compiler tries to deduce the alignment of each field, to improve access. However, it is not always possible for the compiler to deduce the alignment of each field in a __packed struct. In contrast, when individual fields in a struct are declared as __packed, fast access is guaranteed to naturally aligned members within the struct. Therefore, when the use of a packed structure is required, ARM recommends that you always pack individual fields of the structure, rather than the entire structure itself.

Note

Declaring individual non-aligned fields of a struct as __packed also has the advantage of making it clearer to the programmer which fields of the struct are not naturally aligned.
Related concepts
4.35 The __packed qualifier and unaligned data access in C and C++ code
4.36 Unaligned fields in structures
4.40 Comparisons of an unpacked struct, a __packed struct, and a struct with individually __packed fields, and of a __packed struct and a #pragma packed struct
Related reference
9.12 __packed
9.93 #pragma pack(n)
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.