package main
import (
"fmt"
"unsafe"
)
type Man struct {
Maa map[string]string
Naa []byte
}
func main() {
m := make(map[string]string)
m["a"] = "3856"
m["g.t"] = "a_3856"
m["pr"] = "20000000"
m["pr.t"] = "t-par-200000001"
m["ses"] = "841959653263999106"
m["ssc"] = "3478712679"
m["s"] = "462"
n := []byte{10,158,10,133,230,1,154,12,24,2,50,8,8,8,186,7,161,0,229,140,133,230,187,161,228,186,134,34,32,232,131,140,229,140,133,230,187,161,228}
o := Man{
Maa : m,
Naa : n,
}
fmt.Println("man size:", unsafe.Sizeof(o))
fmt.Println("man size:", unsafe.Sizeof(m))
fmt.Println("man size:", unsafe.Sizeof(n))
}
这里记录是说明一件事。这种查询变量或结构内存占用的方法不可取。
它只能说明结构的类型占用的内存大小。不能说明结构变量的数据占用的内存大小。