Comment by kbolino
5 days ago
I don't see this mentioned anywhere else, but Go may start experimenting with rearranging struct fields at some point. The marker type structs.HostLayout has been added in Go 1.24 to indicate that you want the struct to follow the platform's layout rules (think of it like #[repr(C)] in Rust). This may become necessary to ensure the padding actually sits between the two falsely shared fields. You could combine it with the padding technique like this:
type PaddedExample struct {
_ structs.HostLayout
Field1 int64
_ [56]byte
Field2 int64
}
No comments yet
Contribute on Hacker News ↗