Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 885 Bytes

1-字符集.md

File metadata and controls

28 lines (19 loc) · 885 Bytes

Go中的字符编码

字符,字符集(unicode),字符编码(utf-8)

编码 编码模板
编码[0-127] 占1个字节 0???????
编码[128,2047] 占2个字节 110????? 10??????
编码[2048,65536] 占3个字节 110?????10?????10?????

String 底层结构

type stringStruct struct {
    array unsafe.Pointer // 指向一个 [len]byte 的数组
    length int    // 长度
}

64位占16个字节,字符串内容存储在只读内存段

“+”拼接操作

调用runtime.concatstring2,新申请buf,拷贝原来的string到buf,最后返回新实例

Strings.Builder

类似数组2倍扩容,更高效