https://www.golangtc.com/t/5ad833404ce40d2654053485
Niche beginner Go, a little do not know, today in order to know in the end how much of the empty structure of space time, go to Baidu said in unsafe.sizeof, but for unsafe.sizeof like sizeof and other languages a little different?
such as:
var str string = "hello"
var str2 string fmt.Println(unsafe.SizeOf(str), unsafe.SizeOf(str2))
Two structures are printed out 16, which is why?
In the end how to get the structure of space accounted for?
Empty structures occupy much space?
Total 1 reply
heimeil 2018-04-19 19:56
Only returns the size of the data type, regardless of the size of the reference data,
string
the type of data is not directly stored, but a structure with a pointer to the actual data addresstype StringHeader struct { Data uintptr Len int }
In the system 64
uintptr
int
is 8 bytes, the 16 add up.https://golang.org/pkg/reflect/#StringHeader