Skip to content

Instantly share code, notes, and snippets.

@gghez
Created January 1, 2020 20:54
Show Gist options
  • Save gghez/a319024b6512c7b44ed3687580f7c86b to your computer and use it in GitHub Desktop.
Save gghez/a319024b6512c7b44ed3687580f7c86b to your computer and use it in GitHub Desktop.
Don't Fuck With The Alignment
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