Strings in Go are represented by reflect.StringHeader
containing a pointer to actual string data and a length of string:
type StringHeader struct {
Data uintptr
Len int
}
unsafe.Sizeof(s)
will only return the size of StringHeader
struct but not the pointed data itself. So (in your example) it will be sum of 8 bytes for Data
and 8 bytes for Len
making it 16 bytes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…