内存对齐¶
struct A {
char a; // 1 byte
char b; // 1 byte
int c; // 4 bytes
}
struct B {
char a; // 1 byte
int b; // 4 bytes
char c; // 1 byte
}
其中 sizeof(A)
为 8, sizeof(B)
为 12.
struct A {
char a; // 1 byte
char b; // 1 byte
int c; // 4 bytes
}
struct B {
char a; // 1 byte
int b; // 4 bytes
char c; // 1 byte
}
其中 sizeof(A)
为 8, sizeof(B)
为 12.