From 0a8f4bd10b9a31afd51de92e1dd1468e6c590966 Mon Sep 17 00:00:00 2001 From: Zhiyang Lu <103179313+alfaloo@users.noreply.github.com> Date: Tue, 1 Jul 2025 08:29:24 +0800 Subject: [PATCH] [mistake] chapter 9.7 - char at the end of the struct is also size aligned --- content/english/hpc/cpu-cache/alignment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/english/hpc/cpu-cache/alignment.md b/content/english/hpc/cpu-cache/alignment.md index e9c5f4d3..c8378559 100644 --- a/content/english/hpc/cpu-cache/alignment.md +++ b/content/english/hpc/cpu-cache/alignment.md @@ -55,7 +55,7 @@ struct Data { }; ``` -When stored succinctly, this structure needs a total of $1 + 2 + 4 + 1 = 8$ bytes per instance, but even assuming that the whole structure has the alignment of 4 bytes (its largest member, `int`), only `a` will be fine, while `b`, `c` and `d` are not size-aligned and potentially cross a cache line boundary. +When stored succinctly, this structure needs a total of $1 + 2 + 4 + 1 = 8$ bytes per instance, but even assuming that the whole structure has the alignment of 4 bytes (its largest member, `int`), only `a` and `d` will be fine, while `b` and `c` are not size-aligned and potentially cross a cache line boundary. To fix this, the compiler inserts some unnamed members so that each next member gets the right minimum alignment: