【发布时间】:2017-08-10 03:28:00
【问题描述】:
我可以像这样初始化一个缓冲的字符串通道
queue := make(chan string, 10)
但是如何在 Go 的结构中初始化缓冲通道?基本上我想将内存分配给缓冲的字符串通道。但最初在结构中我只是定义它,在结构初始化中,我想为它分配内存
type message struct {
queue *chan string
// or will it be
//queue []chan string
}
func (this *message) init() {
queue = make(chan string,10)
this.queue = &queue
}
【问题讨论】:
-
不要打电话给你的接收者
this。给它一个有意义的名字。类型的第一个字母很常见,所以m在你的情况下。
标签: go memory-management channel