Re: [go-nuts] Appending to a slice of an array on the stack

2020-04-18 Thread Ian Lance Taylor
On Sat, Apr 18, 2020 at 10:26 AM Miguel D wrote: > > Hello everyone. > I'm learning the go language and I have some questions regarding the > implementation of slices. > > $ cat slice_stack.go > package main > > import "fmt" > > func main() { > stack_array := [4]int{1,2,3,4} > // !- I

Re: [go-nuts] Appending to a slice of an array on the stack

2020-04-18 Thread Brian Candler
And very nice explanation here: https://blog.golang.org/slices-intro -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To

Re: [go-nuts] Appending to a slice of an array on the stack

2020-04-18 Thread Marcin Romaszewicz
I added a little more to your example to illustrate my email points. https://play.golang.org/p/eT5tKUniC1E 1) stack_array may or may not be on the stack, Go makes that choice. 2) slice := stack_array[:] Doesn't copy the data, it creates a slice structure which wraps it. 3) Next, when you call

[go-nuts] Appending to a slice of an array on the stack

2020-04-18 Thread Miguel D
Hello everyone. I'm learning the go language and I have some questions regarding the implementation of slices. *$ cat slice_stack.go * package main import "fmt" func main() { stack_array := [4]int{1,2,3,4} // !- I assume this is on the stack, like a local int[4] would be in C.