英文:
How does memory allocation work for buffered channels
问题
如果我有一个带缓冲的通道,像这样:
ch := make(chan int, 1000000)
是不是一开始就分配了8MB的内存,还是内存分配会根据数据量的多少而增长/缩小?
英文:
If I have a buffered channel like this:
ch := make(chan int, 1000000)
is 8MB of memory allocated off the bat, or does the memory allocation grow/shrink depending on the amount of data?
答案1
得分: 7
缓冲区的完整大小(加上我相信是用于通道本身的两个字)将被一次性分配并保留,直到进行垃圾回收。
英文:
The full size of the buffer (plus I believe two words for the channel itself) will be allocated up front and retained until it is garbage collected.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论