# 数据结构对齐

**数据结构对齐**是指对象必须放在满足其类型对齐要求的地址上；对于 N 字节的访问，自然对齐通常意味着地址能被 N 整除，写作 addr % N == 0；位于 0x10004 的 4 字节整数是对齐的，位于 0x10005 的则不是。<sup>[1](https://docs.kernel.org/core-api/unaligned-memory-access.html)</sup> 每个完整对象类型都带有一项对齐要求，它是一个 size_t 类型的整数，表示该类型对象可以被分配的相邻地址之间的字节数，而合法对齐值是 2 的非负整数次幂。<sup>[2](https://cppreference.com/c/language/object)</sup> 编译器会插入**填充字节**，即结构体成员之间或之后的未使用字节，以满足这些要求，而硬件对非对齐访问的容忍程度以及结构体的确切布局，都由处理器架构和平台的应用二进制接口（ABI）决定。<sup>[1](https://docs.kernel.org/core-api/unaligned-memory-access.html)</sup><sup> • </sup><sup>[2](https://cppreference.com/c/language/object)</sup>

| 关键事实 | 详情 |
|---|---|
| 自然对齐 | N 字节的访问必须位于能被 N 整除的地址；char（对齐值为 1）可以起始于任意地址。<sup>[1](https://docs.kernel.org/core-api/unaligned-memory-access.html)</sup><sup> • </sup><sup>[2](https://cppreference.com/c/language/object)</sup> |
| 结构体对齐规则 | 结构体的对齐值至少是其成员对齐值的最大值；为了满足这些要求，会在成员之后插入填充。<sup>[3](https://www.open-std.org/JTC1/SC22/WG14/issues/c23/issue1104.html)</sup><sup> • </sup><sup>[2](https://cppreference.com/c/language/object)</sup> |
| 缓存行 | Rust 标准库的一份源码将 x86、wasm 和 RISC-V 上的缓存行视为 64 字节；它指出英特尔的 Sandy Bridge 空间预取器会成对拉取 64 字节的缓存行，并将相关的同步数据对齐到 128 字节。<sup>[4](https://doc.rust-lang.org/src/std/sync/mpmc/utils.rs.html)</sup> |
| 非对齐代价 | 在英特尔 Core i7-2670QM 上测不出可察觉的性能损失（对齐 9.504 秒，非对齐 9.492 秒）；在树莓派上约为 2.2 倍；在 ARM Cortex-M0 上，对紧凑结构体字段的存储达到 7 倍。<sup>[5](https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-paper.pdf)</sup><sup> • </sup><sup>[6](https://interrupt.memfault.com/blog/the-hidden-cost-of-misalignment)</sup> |
| 触发错误的平台 | 部分 RISC、ARM 和 MIPS 处理器会引发对齐错误；DSP 通常根本不支持非对齐访问；在 Apple M4 上，跨越 16 字节边界的原子访问会触发 SIGBUS 错误。<sup>[5](https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-paper.pdf)</sup><sup> • </sup><sup>[7](https://github.com/v-code01/unalign)</sup> |
| 重排序节省 | 苹果的 64 位示例通过将成员按从大到小排序，从 36 字节（填充到 40 字节）缩减为 28 字节（填充到 32 字节）；一份紧凑排列指南中的 24 字节示例包含 13 个填充字节，浪费超过 50%。<sup>[8](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/64bitPorting/PerformanceOptimization/PerformanceOptimization.html)</sup><sup> • </sup><sup>[9](http://catb.org/esr/structure-packing/)</sup> |
| malloc 保证 | 对于任何合法的基础对齐值 N，当 M ≥ N 时，malloc(M) 返回的指针对 N 而言具有足够的对齐。<sup>[3](https://www.open-std.org/JTC1/SC22/WG14/issues/c23/issue1104.html)</sup> |

## 硬件为什么在意

内存系统以固定大小的单元搬运数据，而不是逐字节搬运。卡内基梅隆大学的《计算机系统导论》课程用三个事实来说明对齐的必要性：内存以 4 或 8 字节的对齐块被访问；加载或存储一个跨缓存行（64 字节）的数据是低效的；当一个数据跨越两个 4 KB 页面时，虚拟内存处理起来更麻烦。<sup>[10](https://www.cs.cmu.edu/%7E213/lectures/06-machine-delta.pdf)</sup> 自对齐让处理器能用一条指令取回带类型的数据；没有自对齐，代码可能需要两次或更多次跨字边界的访问。<sup>[9](http://catb.org/esr/structure-packing/)</sup> 在标准指令集架构上，这产生了熟悉的规则：2 字节的 short 起始于偶数地址，4 字节的 int 和 float 位于能被 4 整除的地址，8 字节的 long 和 double 位于能被 8 整除的地址。<sup>[9](http://catb.org/esr/structure-packing/)</sup>

数组继承这一保证：int 数组的每个元素的地址都是 4 字节的倍数，因此每个元素都位于单个缓存行内。<sup>[11](https://github.com/algorithmica-org/algorithmica/blob/master/content/english/hpc/cpu-cache/alignment.md)</sup> System V ABI 增加了一条细化规定：数组通常使用其元素的对齐值，但长度至少为 16 字节的局部或全局数组，或任何 C99 变长数组，其对齐值至少为 16 字节。<sup>[12](https://lafibre.info/images/doc/202402_intel_application_binary_interface.pdf)</sup>

## C 和 C++ 标准中的对齐

C 对象模型区分**基础**对齐和**扩展**对齐。最弱的对齐是 char、signed char 和 unsigned char 的对齐，等于 1；最严格的基础对齐由实现定义，等于 max_align_t 的对齐值（自 C11 起）。<sup>[2](https://cppreference.com/c/language/object)</sup> 程序员可以通过对齐说明符显式提高对齐：_Alignas 适用于非位域且不具有 register 存储类的对象，在 C23 中已被弃用，改用新拼写 alignas；当同一声明中出现多个说明符时，最严格的那个生效，而值为零的表达式没有效果。<sup>[13](https://cppreference.com/c/language/_Alignas)</sup> 在 C++ 中，alignas 还可以应用于类、结构体、联合体和枚举类型，而 C 不允许这样做；在 C 中，结构体对齐通过成员声明来控制。<sup>[13](https://cppreference.com/c/language/_Alignas)</sup> MSVC 的 align 说明符接受从 1 到 8192 字节之间的 2 的幂。<sup>[14](https://learn.microsoft.com/en-us/cpp/cpp/align-cpp?view=msvc-170)</sup>

alignas 有局限性：C 委员会在第 1041 号问题中澄清，alignas 不能改变结构体内填充的插入方式，因为类型兼容性的定义要求对齐值相同，并指出实际上没有编译器遵循这一解读。<sup>[15](https://www.open-std.org/JTC1/SC22/WG14/issues/c23/issue1041.html)</sup> 一个示例展示了对齐与填充的交互：一个结构体包含一个 char 成员和一个 alignas(128) 的 128 字节数组，其 sizeof 为 256，即 1 字节加上 127 字节的填充再加上数组。<sup>[13](https://cppreference.com/c/language/_Alignas)</sup>

## 结构体填充与成员排序

编译器按声明顺序排列成员，在成员之后插入填充，使下一个成员落在其所需边界上，并在结构体末尾填充，以便结构体数组的每个元素都保持对齐。<sup>[2](https://cppreference.com/c/language/object)</sup><sup> • </sup><sup>[1](https://docs.kernel.org/core-api/unaligned-memory-access.html)</sup> 结构体自身的对齐值至少是其成员对齐值的最大值，包括任何柔性数组成员类型。<sup>[3](https://www.open-std.org/JTC1/SC22/WG14/issues/c23/issue1104.html)</sup><sup> • </sup><sup>[11](https://github.com/algorithmica-org/algorithmica/blob/master/content/english/hpc/cpu-cache/alignment.md)</sup> 这以空间换 CPU 周期，并且在大多数编译器中默认启用。<sup>[11](https://github.com/algorithmica-org/algorithmica/blob/master/content/english/hpc/cpu-cache/alignment.md)</sup>

**按大小递减排序**是标准的补救办法。苹果的指导是从对齐到最大字节边界的成员开始，例如 8 字节的 long 和指针，然后依次向下到 4 字节的 int、2 字节的 short 和 1 字节的 char。<sup>[8](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/64bitPorting/PerformanceOptimization/PerformanceOptimization.html)</sup> 实测效果很具体。在 Algorithmica 的示例中，重新排列成员使每个成员无需填充即对齐，将结构体从 16 字节缩小到 8 字节。<sup>[11](https://github.com/algorithmica-org/algorithmica/blob/master/content/english/hpc/cpu-cache/alignment.md)</sup> 苹果的 64 位示例在不重排序时膨胀到 36 字节并填充到 40 字节（动态分配时占用 64 字节），重排序后缩减为 28 字节填充到 32 字节。<sup>[8](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/64bitPorting/PerformanceOptimization/PerformanceOptimization.html)</sup>

**紧凑排列**则移除填充。GCC 的 __attribute__((packed)) 告诉编译器不要在结构体内插入填充；编译器随后生成额外指令以避免非对齐访问，这有性能代价，对于固定的传输格式数据是可以接受的。<sup>[1](https://docs.kernel.org/core-api/unaligned-memory-access.html)</sup> 同样的效果可以通过 #pragma pack(1) 或 -fpack-struct 编译选项达到，其中任何一种都会生成不兼容的 ABI；GCC 的 -Wpadded 标志报告在哪里插入了填充。<sup>[5](https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-paper.pdf)</sup> 紧凑排列将 Algorithmica 的示例从 16 字节缩小到 9 字节，代价是每次读取可能取两个缓存行。<sup>[11](https://github.com/algorithmica-org/algorithmica/blob/master/content/english/hpc/cpu-cache/alignment.md)</sup> 苹果建议将紧凑排列的 pragma 保留给与硬件寄存器、文件或网络格式或共享内存布局相对应的结构体，其他情况使用自然对齐。<sup>[8](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/64bitPorting/PerformanceOptimization/PerformanceOptimization.html)</sup>

## ABI 规则与二进制兼容性

布局是编译器之间的契约，改变它会破坏二进制兼容性。MSVC 的 pack pragma 接受值 1、2、4、8 和 16；未给出 /Zp 时默认为 8，x64 原生和 ARM64EC 为 16。在 pack 下，成员对齐到 n 的倍数或成员大小的倍数中较小的那个边界。<sup>[16](https://learn.microsoft.com/en-us/cpp/preprocessor/pack?view=msvc-170)</sup> 由于 C++ 标准不涉及紧凑排列，需要 pack 或等效扩展来指定小于目标字长的对齐值。<sup>[16](https://learn.microsoft.com/en-us/cpp/preprocessor/pack?view=msvc-170)</sup>

苹果的 OS X 默认使用自然对齐，int 位于 4 字节边界，但有文档记载的例外：在 32 位可执行文件中，8 字节类型 fpos_t、off_t 和 long long 对齐到 4 字节边界，而在 64 位环境中它们自然对齐到 8 字节边界。<sup>[17](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/64bitPorting/transition/transition.html)</sup> RISC-V psABI 同样固定了栈和参数对齐约定，包括函数入口时栈相对于栈指针零点的对齐。<sup>[18](https://riscv-non-isa.github.io/riscv-elf-psabi-doc/)</sup> 同一平台内也会出现同样的不兼容性：在嵌入式目标上，将紧凑结构体改为 packed, aligned(4) 会改变数组步长，将位于偏移 0、19、38、57 的元素移到 20 字节间距，这破坏了与现有数据的二进制兼容性。<sup>[6](https://interrupt.memfault.com/blog/the-hidden-cost-of-misalignment)</sup>

## 跨架构的非对齐访问

架构以四种有据可查的方式处理非对齐访问：透明处理但有性能代价；产生可纠正的异常；产生不可纠正的异常；或者静默地执行与请求不同的访问，最后一种会产生难以检测的隐蔽缺陷。<sup>[1](https://docs.kernel.org/core-api/unaligned-memory-access.html)</sup> 每种行为都有历史实例。在 ARM7 和 ARM9 上，非对齐的 LDR 在内存系统中的执行方式与对齐访问相同，但返回的是旋转过的数据，将请求地址处的字节放在寄存器的最低有效字节中，这在将代码移植到 ARMv7 时是一个可移植性陷阱。<sup>[19](https://developer.arm.com/documentation/den0013/0400/Porting/Alignment)</sup> 在 Sun [SPARC](https://www.edgepedia.org/zh/sparc) 等较老处理器上，违反对齐会导致非法指令错误，在 x86 上使用正确的硬件标志仍然可以触发。<sup>[9](http://catb.org/esr/structure-packing/)</sup>

**现代策略**各不相同，形成了一系列不同的处理方式。Cortex-A 在通过 CP15:SCTLR 中的 U 位启用时支持非对齐的字和半字访问，但 LDM、STM、LDRD 和 STRD 要求字对齐，浮点加载和存储必须始终对齐。<sup>[19](https://developer.arm.com/documentation/den0013/0400/Porting/Alignment)</sup> 部分 RISC、ARM 和 MIPS 处理器以对齐错误响应，DSP 通常根本不支持非对齐访问；在处理非对齐访问的处理器上，性能代价因处理器和访问模式而异。<sup>[5](https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-paper.pdf)</sup> 实测的字段存储代价使这一差异变得具体：在 RISC-V 32（rv32imac）、Xtensa（ESP32）和 ARM Cortex-M0 上，存储 pack(1) 结构体的一个字段需要 7 次操作，而 packed, aligned(4) 只需 1 次，代价为 7 倍；MIPS32 为 2 倍，而 x86_64、i686 和 macOS arm64 为 1 倍。<sup>[6](https://interrupt.memfault.com/blog/the-hidden-cost-of-misalignment)</sup> 即使在允许非对齐访问的地方，Arm 架构参考手册指出它通常会多花几个周期，而跨越页边界的访问可能在边界的任一侧产生中止。<sup>[20](https://support.arm.com/documentation/ddi0487/md/-Part-B-The-AArch64-Application-Level-Architecture/-Chapter-B2-The-AArch64-Application-Level-Memory-Model/-B2-8-Alignment-support/-B2-8-2-Alignment-of-data-accesses)</sup> MSVC 的文档警告说，改变结构体对齐可能导致性能损失或非对齐访问的硬件异常。<sup>[16](https://learn.microsoft.com/en-us/cpp/preprocessor/pack?view=msvc-170)</sup>

## 对齐、缓存与并发

缓存行设定了一个粒度，超过它，对齐问题就不再是关于单条指令，而是关于内存流量。Rust 标准库的一份源码将 x86、wasm 和 RISC-V 上的缓存行视为 64 字节。<sup>[4](https://doc.rust-lang.org/src/std/sync/mpmc/utils.rs.html)</sup> SIMD 使对齐变得更加重要：某些 SSE 指令要求数据结构按规范对齐；违反此类指令的对齐要求可能导致未定义行为。<sup>[5](https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-paper.pdf)</sup> 许多 SIMD 应用读写 32 字节的块，这些字节属于同一缓存行对性能至关重要，alignas 和 std::aligned_alloc 可以保证这一点。<sup>[11](https://github.com/algorithmica-org/algorithmica/blob/master/content/english/hpc/cpu-cache/alignment.md)</sup> 回报可能很大：在 x264 开发过程中，缓存行对齐的 16 字节传输使最常用的函数之一快了 69%。<sup>[21](https://hackaday.com/2022/05/10/data-alignment-across-architectures-the-good-the-bad-and-the-ugly/)</sup> 苹果测量了一个更简单的案例，重新排列循环变量以避免非对齐访问，在退化情况下性能提升超过 20%。<sup>[8](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/64bitPorting/PerformanceOptimization/PerformanceOptimization.html)</sup>

**伪共享**（多个核心针对不同变量反复使对方的缓存行失效）是并发一侧的代价。Rust 标准库的一份源码指出，英特尔的 Sandy Bridge 空间预取器一次拉取成对的 64 字节缓存行，并将其相关同步结构对齐到 128 字节而非 64 字节。<sup>[4](https://doc.rust-lang.org/src/std/sync/mpmc/utils.rs.html)</sup> 对于多线程访问，数据的安排应使读取来自一个缓存行，写入到另一个缓存行，从而最小化核心之间的缓存行弹跳。<sup>[9](http://catb.org/esr/structure-packing/)</sup>

涉及原子性时，对齐就不再只是偏好。AArch64 允许大多数非对齐数据访问，但没有 FEAT_LSE2 时，它们不保证字节级别以上的单副本原子性；有了 FEAT_LSE2，完全位于一个 16 字节对齐量内、访问 Normal Write-Back Cacheable Shareable 内存的非对齐访问是单副本原子的。<sup>[20](https://support.arm.com/documentation/ddi0487/md/-Part-B-The-AArch64-Application-Level-Architecture/-Chapter-B2-The-AArch64-Application-Level-Memory-Model/-B2-8-Alignment-support/-B2-8-2-Alignment-of-data-accesses)</sup> 非对齐访问在 ARMv7 上也不保证原子性，外部代理可能观察到部分完成的访问。<sup>[19](https://developer.arm.com/documentation/den0013/0400/Porting/Alignment)</sup> C 标准在类型系统中反映了这一点：没有过度对齐成员的结构体具有基础对齐，每个算术或指针类型的原子版本具有基础对齐（自 C11 起）。<sup>[2](https://cppreference.com/c/language/object)</sup> [Apple M4](https://www.edgepedia.org/zh/apple-m4) 以错误强制执行这一规则：非对齐的标量加载和存储全速运行，即使跨越 64 字节缓存行或 4 KB 页面，但跨越 16 字节边界的原子操作不会变慢，而是触发 SIGBUS 并杀死进程；8 字节原子必须完全位于一个 16 字节对齐块内，16 字节原子必须完全 16 字节对齐，没有慢路径。<sup>[7](https://github.com/v-code01/unalign)</sup>

## 近期发展

有三条变化线索值得注意。在标准和库方面，C23 将 _Alignas 重新拼写为 alignas，<sup>[13](https://cppreference.com/c/language/_Alignas)</sup> glibc 于 2025 年 10 月在 stdlib.h 中实现了 C23 的 memalignment 函数；它以 2 的幂的形式返回指针的对齐值，空指针返回零，该函数被添加以支持指针低位与对齐无关的非传统平台。<sup>[22](https://sourceware.org/pipermail/libc-alpha/2025-October/171152.html)</sup><sup> • </sup><sup>[23](https://sourceware.org/pipermail/libc-alpha/2025-October/171136.html)</sup> 在内核方面，2024 年 3 月的一个补丁提出了 RISCV_UNALIGNED_ACCESS 选项，在启动期间 [Linux 内核](https://www.edgepedia.org/zh/linux-kernel)将运行测试以确定非对齐访问的速度并动态确定支持。<sup>[24](https://lists.openwall.net/linux-kernel/2024/03/06/1407)</sup> 在硬件方面，Apple M4 提供全速的非对齐标量访问，同时对原子操作保持严格对齐，<sup>[7](https://github.com/v-code01/unalign)</sup> 这种区分反映了 Arm FEAT_LSE2 的设计：放宽标量访问，同时定义原子性窗口。<sup>[20](https://support.arm.com/documentation/ddi0487/md/-Part-B-The-AArch64-Application-Level-Architecture/-Chapter-B2-The-AArch64-Application-Level-Memory-Model/-B2-8-Alignment-support/-B2-8-2-Alignment-of-data-accesses)</sup>

## 分配与工具

分配器将类型对齐要求与运行时地址衔接起来。malloc() 及相关分配器通常对齐到系统上最大的对齐要求，因此任何正确对齐的结构体都是对齐的，这种开销可能导致显著浪费。<sup>[25](https://cse.buffalo.edu/courses/cse220/2025-Spring/13-alignment.pdf)</sup> C 委员会在第 1104 号问题中使保证变得精确：对于任何合法的基础对齐值 N，如果 M 大于或等于 N，malloc(M) 保证返回的指针对 N 具有足够的对齐。<sup>[3](https://www.open-std.org/JTC1/SC22/WG14/issues/c23/issue1104.html)</sup> 对于更严格的需求，std::aligned_alloc 接受一个对齐值和一个大小，返回对齐的内存。<sup>[11](https://github.com/algorithmica-org/algorithmica/blob/master/content/english/hpc/cpu-cache/alignment.md)</sup>

在检查方面，结构体紧凑排列指南的几位受访者都对 pahole 评价良好，这是一个与编译器协作生成结构体报告的工具，描述填充、对齐和缓存行边界。<sup>[9](http://catb.org/esr/structure-packing/)</sup> 它揭示的量化浪费可能很惊人：在一个 24 字节的示例结构体中，13 字节是填充，浪费超过 50%。<sup>[9](http://catb.org/esr/structure-packing/)</sup> 在实测代价方面，各方资料对桌面 x86 上对齐还有多重要存在分歧：在英特尔 Core i7-2670QM 上的一项基准测试（gcc 4.8.2，-O0，400,000,000 次迭代）发现对齐运行时间为 9.504220399 秒，非对齐为 9.491816620 秒，没有可测量的性能损失，<sup>[5](https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-paper.pdf)</sup> 而 x264 的结果显示，在一个大量使用的函数中，缓存行对齐的 16 字节传输带来了 69% 的提升。<sup>[21](https://hackaday.com/2022/05/10/data-alignment-across-architectures-the-good-the-bad-and-the-ugly/)</sup>

## References

1. [Unaligned Memory Accesses, The Linux Kernel documentation](https://docs.kernel.org/core-api/unaligned-memory-access.html)
2. [Objects and alignment, cppreference.com](https://cppreference.com/c/language/object)
3. [WG14 issue 1104: Flexible array members and alignment](https://www.open-std.org/JTC1/SC22/WG14/issues/c23/issue1104.html)
4. [Rust standard library source: std/sync/mpmc/utils.rs](https://doc.rust-lang.org/src/std/sync/mpmc/utils.rs.html)
5. [Sven-Hendrik Haase, Alignment in C, Universität Hamburg](https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-paper.pdf)
6. [The Hidden Cost of Misalignment, Interrupt (Memfault)](https://interrupt.memfault.com/blog/the-hidden-cost-of-misalignment)
7. [v-code01/unalign: unaligned access benchmarks on Apple M4](https://github.com/v-code01/unalign)
8. [64-Bit Transition Guide: Performance Optimization, Apple](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/64bitPorting/PerformanceOptimization/PerformanceOptimization.html)
9. [The Lost Art of Structure Packing](http://catb.org/esr/structure-packing/)
10. [Introduction to Computer Systems 15-213, CMU, Fall 2026 lecture](https://www.cs.cmu.edu/%7E213/lectures/06-machine-delta.pdf)
11. [Algorithmica: CPU Cache, Alignment](https://github.com/algorithmica-org/algorithmica/blob/master/content/english/hpc/cpu-cache/alignment.md)
12. [System V Application Binary Interface, Intel ABI, February 2024](https://lafibre.info/images/doc/202402_intel_application_binary_interface.pdf)
13. [_Alignas / alignas, cppreference.com](https://cppreference.com/c/language/_Alignas)
14. [align (C++), Microsoft Learn](https://learn.microsoft.com/en-us/cpp/cpp/align-cpp?view=msvc-170)
15. [WG14 issue 1041: Alignment of structure and union members](https://www.open-std.org/JTC1/SC22/WG14/issues/c23/issue1041.html)
16. [pack pragma, Microsoft Learn](https://learn.microsoft.com/en-us/cpp/preprocessor/pack?view=msvc-170)
17. [64-Bit Transition Guide: Transitioning, Apple](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/64bitPorting/transition/transition.html)
18. [RISC-V ABIs Specification](https://riscv-non-isa.github.io/riscv-elf-psabi-doc/)
19. [ARM Cortex-A Series Programmer's Guide: Alignment](https://developer.arm.com/documentation/den0013/0400/Porting/Alignment)
20. [Arm Architecture Reference Manual (DDI 0487): Alignment of data accesses](https://support.arm.com/documentation/ddi0487/md/-Part-B-The-AArch64-Application-Level-Architecture/-Chapter-B2-The-AArch64-Application-Level-Memory-Model/-B2-8-Alignment-support/-B2-8-2-Alignment-of-data-accesses)
21. [Data Alignment Across Architectures, Hackaday](https://hackaday.com/2022/05/10/data-alignment-across-architectures-the-good-the-bad-and-the-ugly/)
22. [glibc patch v4: Implement C23 memalignment](https://sourceware.org/pipermail/libc-alpha/2025-October/171152.html)
23. [glibc patch v3: Implement C23 memalignment](https://sourceware.org/pipermail/libc-alpha/2025-October/171136.html)
24. [Linux kernel patch v7: riscv unaligned access speed probing](https://lists.openwall.net/linux-kernel/2024/03/06/1407)
25. [Alignment, Padding, and Packing, CSE 220, University at Buffalo](https://cse.buffalo.edu/courses/cse220/2025-Spring/13-alignment.pdf)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Processors & processor engineering › Computer architecture theory › Memory hierarchy and caching

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/data-structure-alignment

English original: https://www.edgepedia.org/data-structure-alignment
