Skip to content

Instantly share code, notes, and snippets.

@hyper0x
Created July 25, 2015 16:36
Show Gist options
  • Save hyper0x/ba5acf272663a3671777 to your computer and use it in GitHub Desktop.
Save hyper0x/ba5acf272663a3671777 to your computer and use it in GitHub Desktop.
The value is assigned means that generate a copy.
package main
import "fmt"
type Pool struct {
array [3]int
}
func main() {
a := [...]int{1, 2, 3}
pool := Pool{
array: a,
}
fmt.Printf("Pool: %v\n", pool)
a[0] = 4
fmt.Printf("Pool: %v\n", pool)
pool.array = a
fmt.Printf("Pool: %v\n", pool)
a[1] = 5
fmt.Printf("Pool: %v\n", pool)
b := a
fmt.Printf("B: %v\n", b)
a[2] = 6
fmt.Printf("B: %v\n", b)
b[2] = 7
fmt.Printf("A: %v\n", a)
}
// Output:
// Pool: {[1 2 3]}
// Pool: {[1 2 3]}
// Pool: {[4 2 3]}
// Pool: {[4 2 3]}
// B: [4 5 3]
// B: [4 5 3]
// A: [4 5 6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment