All books

Professional

Apps About Coach Log in Start reading

Computer Science · Glossary

What is Alignment, padding?

Also known as: alignment · padding

Definition 6.6 University Computer Science — Year 1 · Chapter 6 — Strings, Structures and Files

The alignment of a type is a power of two by which the address of every object of that type must be divisible; on this machine it equals the size for char, short, int, long, double and pointers. Padding is the unused bytes that the compiler inserts in a structure so that each field lies at an offset multiple of its alignment, and at the end so that the size is a multiple of the largest alignment of a field, which keeps every element of an array of structures aligned.

The two layouts of , with offsets in bytes (s: station, f: flag). In loose, the double forces seven bytes of padding after the first char; sorted by decreasing alignment, the fields leave only two bytes at the end.
The two layouts of Listing 6.7, with offsets in bytes (s: station, f: flag). In loose, the double forces seven bytes of padding after the first char; sorted by decreasing alignment, the fields leave only two bytes at the end.
Read in context →