Re: [go-nuts] How Golang implements slice?

2016-09-13 Thread Edward Muller
Doh. I keep forgetting about a[low : high : max], but also want to point out that if that if the slice is modified by the func beyond cap then the backing array will be swapped out anyway and your slice header doesn't know about the swap or the new cap. On Tue, Sep 13, 2016 at 5:00 AM Val wrote:

Re: [go-nuts] How Golang implements slice?

2016-09-13 Thread Val
Hello Ding Actually you don't need unsafe or reflect to access the 4th element : https://play.golang.org/p/wZAkKtAZei See section "Full slice expressions" in spec about 3-index slicing like a[low : high : max] You were correct in deducing that s

Re: [go-nuts] How Golang implements slice?

2016-09-13 Thread Fei Ding
Thanks, Edward, you make a good point. What's more, I wrote more code yesterday, and found that we can in fact get the 4th element even if the descriptor tells us there are only 3, by using package unsafe , and doing some simple pointer calculation. It shows that fu

Re: [go-nuts] How Golang implements slice?

2016-09-12 Thread Edward Muller
On Mon, Sep 12, 2016 at 8:17 PM Fei Ding wrote: > Hi guys: > > I met a problem when I try to understand slice when using as function > parameters. After writing some code, I made a conclusion by myself, but > need some real check and explanation here, with your help. > > As far as I know, Golang'

[go-nuts] How Golang implements slice?

2016-09-12 Thread Fei Ding
Hi guys: I met a problem when I try to understand slice when using as function parameters. After writing some code, I made a conclusion by myself, but need some real check and explanation here, with your help. As far as I know, Golang's function parameters are passed by value, and slice could