type slice struct {
array unsafe.Pointer
len int
cap int
}
从切片的结构定义来看,是对底层数组的封装,增加了长度及容量字段
const maxAlloc untyped int = 281474976710656
maxAlloc is the maximum size of an allocation. On 64-bit, it's theoretically possible to allocate 1<<heapAddrBits bytes. On 32-bit, however, this is one less than 1<<32 because the number of bytes in the address space doesn't actually fit in a uintptr.
import "fmt"
func main() {
var array [10]int
slice := array[3:5]
fmt.Println(len(slice), cap(slice))
fmt.Println(&array[3] == &slice[0])
}
2 7
true
KGo笔记
全部评论