package main
import (
"fmt"
"unsafe"
)
func main() {
which := make([]byte, 0)
which = append(which, []byte("123")...)
which1 := which
fmt.Printf("which: %s var pointer :%p arr pointer %p cap: %d len:%d, which1: %s var pointer :%p arr pointer %p cap: %d len:%d\n",
which, &which, unsafe.Pointer(&which[0]), cap(which), len(which), which1, &which1, unsafe.Pointer(&which1[0]), cap(which1), len(which1))
which = append(which, []byte("456")...)
fmt.Printf("which: %s var pointer :%p arr pointer %p cap: %d len:%d, which1: %s var pointer :%p arr pointer %p cap: %d len:%d\n",
which, &which, unsafe.Pointer(&which[0]), cap(which), len(which), which1, &which1, unsafe.Pointer(&which1[0]), cap(which1), len(which1))
which1 = append(which1, []byte("789")...)
fmt.Printf("which: %s var pointer :%p arr pointer %p cap: %d len:%d, which1: %s var pointer :%p arr pointer %p cap: %d len:%d\n",
which, &which, unsafe.Pointer(&which[0]), cap(which), len(which), which1, &which1, unsafe.Pointer(&which1[0]), cap(which1), len(which1))
which1 = append(which1, []byte("123")...)
fmt.Printf("which: %s var pointer :%p arr pointer %p cap: %d len:%d, which1: %s var pointer :%p arr pointer %p cap: %d len:%d\n",
which, &which, unsafe.Pointer(&which[0]), cap(which), len(which), which1, &which1, unsafe.Pointer(&which1[0]), cap(which1), len(which1))
}
标签:扩容,arr,cap,unsafe,which1,golang,len,数组,pointer
From: https://www.cnblogs.com/guanchaoguo/p/18075905