请看例子:http : //play.golang.org/p/6d4uX15EOQ
package main
import (
"fmt"
"reflect"
"unsafe"
)
func main() {
c := "foofoofoofoofoofofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo"
fmt.Printf("c: %T, %d\n", c, unsafe.Sizeof(c))
fmt.Printf("c: %T, %d\n", c, reflect.TypeOf(c).Size())
}
输出:
c: string, 8 //8 bytes?!
c: string, 8
这么大的字符串好像不能有这么小的尺寸!怎么了?
千万里不及你
相关分类