笔记
在 Go 中,string是一种不可变的数据结构,包含以下内容:
- 指向不可变字节序列的指针,指向一个byte类型的数组
- 此序列中的总字节数
string在Go中的内部结构是reflect.StringHeader
位于reflect/value.go
// StringHeader is the runtime representation of a string.
// It cannot be used safely or portably and its representation may
// change in a later release.
// Moreover, the Data field is not sufficient to guarantee the data
// it references will not be garbage collected, so programs must keep
// a separate, correctly typed pointer to the underlying data.
type StringHeader struct {
Data uintptr
Len int
}
//uintptr an unsigned integer large enough to store the uninterpreted bits of a pointer value