Skip to content

Instantly share code, notes, and snippets.

@mattheusv
Last active June 7, 2019 11:53
Show Gist options
  • Save mattheusv/4a81a1f843ff29828f6f34ad43297e4e to your computer and use it in GitHub Desktop.
Save mattheusv/4a81a1f843ff29828f6f34ad43297e4e to your computer and use it in GitHub Desktop.
playing with Go runtime
package main
import "runtime"
func main() {
var x [10]int
var y = &x[2] //ref to array contetn
var z = y // ref copy
println(&x, y, z) //will print reference memory address
a(x)
println(&x, y, z) //will print different reference memory address
runtime.GC() //garbage collector call
println(&x, y, z) //will print different reference memory address AGAIN
}
//go:noinline
func a(x [10]int) {
println("func a")
var y [100]int
b(y)
}
//go:noinline
func b(x [100]int) {
println("func b")
var y [1000]int
c(y)
}
//go:noinline
func c(x [1000]int) {
println("func c")
}
@mattheusv
Copy link
Author

Output example:

0xc00003a738 0xc00003a748 0xc00003a748
func a
func b
func c
0xc00007df38 0xc00007df48 0xc00007df48
0xc000075f38 0xc000075f48 0xc000075f48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment