// example1.go
package main
func main() {
for i := 0; i < 2; i++ {
m := make(map[int]int)
m[1] = 100
}
}
// example2.go
package main
func main() {
var m map[int]int
for i := 0; i < 2; i++ {
m = make(map[int]int)
m[1] = 100
}
}
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
In the first example, make does not escape the scope of the for statement. In the second example, make is assigned to m, which is outside of the scope of the for statement, which means the make operation escapes its scope and subsequently, is heap allocated. If you want more information about why something escapes, try compiling with -gcflags "-m -m" for an explanation of the escape analysis information.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
Hi Chris:
I am gopher from Beijing China . I am very like programing and adore the old hack culture . and NBA too!
I am very happy in google groups and receive the answer so quickly.
go on practice programing and improve my badly english
question:
package main
func main() {
var a []int
Label1:
a = make([]int, 0, 2)
_ = a
}
could’t you give me an example that happens escape ?