Last active
June 7, 2019 11:53
-
-
Save mattheusv/4a81a1f843ff29828f6f34ad43297e4e to your computer and use it in GitHub Desktop.
playing with Go runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output example: