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 __packedstruct.
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, it is recommended 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.
This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.
ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.