全部书籍

专业

应用 关于 Coach 登录 开始阅读

书籍暂未推出简体中文版——当前显示英文版。

Computer Science · 术语表

什么是 Alignment, padding?

又称: alignment · padding

Definition 6.6 University Computer Science — Year 1 · 第 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.
在原文中阅读 →