Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Created January 13, 2019 14:21
Show Gist options
  • Save ashkrit/05662eedff3173650654c1df25870f97 to your computer and use it in GitHub Desktop.
Save ashkrit/05662eedff3173650654c1df25870f97 to your computer and use it in GitHub Desktop.
var x layouttest
var y compactyouttest
fmt.Printf("Int alignment %v \n", unsafe.Alignof(10))
fmt.Printf("Int8 aligment %v \n", unsafe.Alignof(int8(10)))
fmt.Printf("Int16 aligment %v \n", unsafe.Alignof(int16(10)))
fmt.Printf("Layoutest aligment %v ans size is %v \n", unsafe.Alignof(x), unsafe.Sizeof(x))
fmt.Printf("Compactlayouttest aligment %v and size is %v \n", unsafe.Alignof(y), unsafe.Sizeof(y))
fmt.Printf("Type %v has %v fields and takes %v bytes \n", reflect.TypeOf(x).Name(), reflect.TypeOf(x).NumField(), reflect.TypeOf(x).Size())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment