Re: [go-nuts] Underlying arrays and their slices passed to functions

2018-01-05 Thread Frank Davidson
Thanks, all!!! Frank On Friday, January 5, 2018 at 4:25:33 AM UTC-5, Ian Davis wrote: > > On Thu, 4 Jan 2018, at 6:55 PM, Frank Davidson wrote: > > Thanks!!! Very helpful blog post!! > > So, in proc, the slice header is copied, then an entirely new array is > created - []byte{5,6,7,8} - and the

Re: [go-nuts] Underlying arrays and their slices passed to functions

2018-01-05 Thread Ian Davis
On Thu, 4 Jan 2018, at 6:55 PM, Frank Davidson wrote: > Thanks!!! Very helpful blog post!! > > So, in proc, the slice header is copied, then an entirely new array is > created - []byte{5,6,7,8} - and the slice header copy is set to point > at that new array, and then discarded, whereas in proc 2,

Re: [go-nuts] Underlying arrays and their slices passed to functions

2018-01-04 Thread Frank Davidson
Thanks!!! Very helpful blog post!! So, in proc, the slice header is copied, then an entirely new array is created - []byte{5,6,7,8} - and the slice header copy is set to point at that new array, and then discarded, whereas in proc 2, the slice header is not reset, and so still points to the

Re: [go-nuts] Underlying arrays and their slices passed to functions

2018-01-04 Thread Jan Mercl
On Thu, Jan 4, 2018 at 7:08 PM Frank Davidson wrote: > I'm sure this has probably been answered before, but I have a question about when a slice's underlying array is copied? In this code: In your code the underlying arrays are never copied when passed around. -- -j

Re: [go-nuts] Underlying arrays and their slices passed to functions

2018-01-04 Thread Ian Lance Taylor
On Thu, Jan 4, 2018 at 10:08 AM, Frank Davidson wrote: > > I'm sure this has probably been answered before, but I have a question about > when a slice's underlying array is copied? In this code: > > https://play.golang.org/p/TnMFo-rYKzq > > package main > > import ( > "fmt"

[go-nuts] Underlying arrays and their slices passed to functions

2018-01-04 Thread Frank Davidson
I'm sure this has probably been answered before, but I have a question about when a slice's underlying array is copied? In this code: https://play.golang.org/p/TnMFo-rYKzq package main import ( "fmt" ) func main() { out := []byte{1, 2, 3, 4} fmt.Println(out) proc(out) fmt.Println(out)