
本文共 3085 字,大约阅读时间需要 10 分钟。
Go������������������������new���make���������������������������������������allocation primitives���������������������new������������������make������slice���map������channel���������������
���������������new���make������������������������������
new(T)������������T������������������������������T������������������������������������������������������T���������������������������������������������������*T������������������������������������������������������������������������������������������������������
make(T, args)������������������������������T���������������make������������������slice���map���channel���������������������������������������������������������������������������������T���������������������������������������������������������������������������������������������������������������������������������
���������������������make���������new���������������������slice���map���channel������������������������������������������������������������������������������
slice���������
slice���Go���������������������������������������������������������������������������������������������������������slice������������������
// ������������������������������var s1 []intif s1 == nil { // s1������������ fmt.Printf("s1 is nil --> %v \n", s1) // []int(nil)}// ������make���������slices2 := make([]int, 3)if s2 == nil { // ���������������������������make���������������������������slice fmt.Printf("s2 is nil --> %v \n", s2) // []int(nil)} else { fmt.Printf("s2 is not nil --> %v \n", s2) // [0 0 0]}// another examplesliceTest := make([]int, 10)sliceTest[0] = 42
������make������������slice���������������������������������������������slice������������������������������������������������������������������������nil������������������make������������������������������������������
������������
make������������������slice���map���channel������������������������������������new������������������������
���������������������������make������������������������������������������������������������������������������������������������������������������������������������������������������������
new������������������������������������������������������������������struct���������������������������������������������������������������������������new������������������������������������������������������
map���������
map���Go���������������������������������������������������������������������������������������������make������������������
map1 := make(map[string]float32)// ���������������������������map������������������������������������������// ���������������������������������������������������
���new���������������������������������new������������������map���������new������������������������������������������������������map���������������������������������������������������������������
���������������������new���make���������������������������������������������������������������������������������������������make������������������slice���map���channel������������������������new���������������������������������������������������������������
发表评论
最新留言
关于作者
