摘要: 01、值类型和引用类型 GO只有slice、map、chan 3种引用类型,其它都是值类型 02、slice引用拷贝 1 package main 2 3 import ( 4 "fmt" 5 ) 6 7 func appendSlice(s []int) { 8 s[0] = 10//成功修改ma 阅读全文
posted @ 2020-05-02 22:01 TBBS 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 01、按照内存对齐,重新计算结构体长度 1 const ( 2 maxAlign = 8 //按照8个byte进行内存对齐 3 hchanSize = unsafe.Sizeof(hchan{}) + uintptr(-int(unsafe.Sizeof(hchan{}))&(maxAlign-1) 阅读全文
posted @ 2020-05-02 21:07 TBBS 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 01、使用chan控制程序结束 package main import "fmt" func main() { c := make(chan bool) go func() { fmt.Println("hello") c <- true }() <-c } 02、遍历chan 1 package 阅读全文
posted @ 2020-05-02 11:40 TBBS 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 01、反射字段和方法 1 package main 2 3 import ( 4 "fmt" 5 "reflect" 6 ) 7 8 type Name struct { 9 name string 10 age int 11 } 12 13 func (n Name) Print() { 14 f 阅读全文
posted @ 2020-05-02 09:21 TBBS 阅读(184) 评论(0) 推荐(0) 编辑