Re: [go-nuts] Some questions about the memory allocation strategy of channel

2021-03-27 Thread Paul Zhang
I guess I have misunderstood something about the process of the allocation and gc :) Maybe I need to learn from the gc theory first. BTW thanks for your reply. 在2021年3月20日星期六 UTC+8 上午1:20:12 写道: > On Thu, Mar 18, 2021 at 8:36 PM Paul Zhang wrote: > > > > Can I just understand that for the defa

Re: [go-nuts] Some questions about the memory allocation strategy of channel

2021-03-19 Thread Ian Lance Taylor
On Thu, Mar 18, 2021 at 8:36 PM Paul Zhang wrote: > > Can I just understand that for the default case, when the compiler executes > the mallocgc() for c.buf, it would use reflect to build the descriptor for > the type of element? And if it allocates the both spaces in one function > call, it wo

Re: [go-nuts] Some questions about the memory allocation strategy of channel

2021-03-19 Thread Tamás Gulácsi
AFAIK when there's no pointer in elem (the channel's element's type), we can cheat/optimize (call as you wish), and allocate the channel's backing memory AND all it's elements' memory at once, AS A BYTE ARRAY (nil is the second argument of mallocgc). Then we can play unsafe tricks an treat it as

Re: [go-nuts] Some questions about the memory allocation strategy of channel

2021-03-19 Thread Jan Mercl
On Fri, Mar 19, 2021 at 4:36 AM Paul Zhang wrote: Please do not post colorized code to the ML. Particularly with inverted colors. Please use plain black on white text, thank you. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe fr

Re: [go-nuts] Some questions about the memory allocation strategy of channel

2021-03-18 Thread Paul Zhang
For this piece of code: case elem.ptrdata == 0: // Elements do not contain pointers. // Allocate hchan and buf in one call. c = (*hchan)(mallocgc(hchanSize+mem, nil, true)) c.buf = add(unsafe.Pointer(c), hchanSize) default: // Elements contain pointers. c = new(hchan) c.buf =

Re: [go-nuts] Some questions about the memory allocation strategy of channel

2021-03-18 Thread Ian Lance Taylor
On Thu, Mar 18, 2021 at 9:55 AM Paul Zhang wrote: > > I was reading the source code of makechan(), and these questions confused me. > I would appreciate it if someone could help me. > > Q1. What does Elements do not contain pointers. mean? Does that means that > the type of channel is not a poin

[go-nuts] Some questions about the memory allocation strategy of channel

2021-03-18 Thread Paul Zhang
I was reading the source code of makechan(), and these questions confused me. I would appreciate it if someone could help me. Q1. What does Elements do not contain pointers. mean? Does that means that the type of channel is not a pointer type (like chan int and chan *int)? Q2. Why does the allo