C language structure memory alignment problem

Insert picture description here
Reference blog post: C language structure memory alignment problem

Member alignment:
  Take 4-byte alignment as an example. If its own type is less than 4 bytes, the first address of the member is an integral multiple of its own type; if its own type is greater than or equal to 4 bytes, the first address of the member is 4 Integer multiples of. If it is an embedded structure, the first address of the embedded structure should also be aligned, but the size of its own type is represented by the maximum member type size of the embedded structure. The array can be disassembled and regarded as n array elements, instead of the whole as a type.

Finally, the overall structure is complemented:
  Taking 4-byte alignment as an example, if the largest member type in the structure is less than 4 bytes, the size complement is an integer multiple of the size of the largest member type in the structure; if it is greater than or equal to 4 bytes, Then the size is filled in multiples of 4. The embedded structure should also be filled.
Reference blog post: What the hell is structure memory alignment?

Guess you like

Origin blog.csdn.net/weixin_43297891/article/details/114296161