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.

    slice := stack_array[:] // Does this copy the data to the heap?
                            // or just get a slice to the mem on the stack?
    for i := 0; i<25; i++ {
        slice = append(slice, 99) // Does this copy the data to the heap on 
first append?
    }

    fmt.Println(stack_array)
    fmt.Println(slice)
}


*$ go run slice_stack.go *
[1 2 3 4]
[1 2 3 4 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 
99 99 99]

Is it common to get slices to arrays on the stack? Am I wrong when I say 
*stack_array* is on the stack?
Thank you.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/221259d6-8cd2-4f51-b67d-757a0f802e7b%40googlegroups.com.

Reply via email to