Created
January 1, 2020 20:54
-
-
Save gghez/a319024b6512c7b44ed3687580f7c86b to your computer and use it in GitHub Desktop.
Don't Fuck With The Alignment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ( | |
| "unsafe" | |
| "fmt" | |
| ) | |
| type A struct { | |
| a string | |
| b bool | |
| c bool | |
| d string | |
| } | |
| type B struct { | |
| a string | |
| b bool | |
| c string | |
| d bool | |
| } | |
| func main(){ | |
| fmt.Printf("well aligned size: %d\n", unsafe.Sizeof(A{})) | |
| fmt.Printf("random aligned size: %d\n", unsafe.Sizeof(B{})) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment