background: on 64-bit operating system
example: define 2 stuct objects with the same members (in different order) and print
package main
import "unsafe"
type A struct {
X bool
Y float64
Z int16
}
type B struct {
Y float64
X bool
Z int16
}
func main() {
print("A: ")
println(unsafe.Sizeof(A{}))
print("B: ")
println(unsafe.Sizeof(B{}))
}
output result:
A: 24
B16
conclusion:
so when defining sturct members, random definitions may result in different memory usage. What I want to ask is, is there anything to refer to in the definition?