Here, and elsewhere (Strange benchmark results), if you not sure what is going on then you say that it must be weird, strange, an error, inaccurate, and so on. The problem appears to be that you are not taking into account that the Go gc and gccgo compilers are optimizing compilers.
For your example, https://play.golang.org/p/SuQHjzALWe0 $ go version go version devel go1.17-cca23a7373 Sat May 22 00:51:17 2021 +0000 linux/amd64 $ go run -gcflags='-m -m' tl.1.go # command-line-arguments ./tl.1.go:11:6: can inline main with cost 30 as: func() { var r []T; r = make([]T, N); println(r[i]); var r2 []T; r2 = make([]T, n); println(r2[i]); var r3 []T; r3 = make([]T, K); println(r3[i]) } ./tl.1.go:9:5: can inline init with cost 5 as: func() { i = n - 1 } ./tl.1.go:15:15: make([]T, n) escapes to heap: ./tl.1.go:15:15: flow: {heap} = &{storage for make([]T, n)}: ./tl.1.go:15:15: from make([]T, n) (non-constant size) at ./tl.1.go:15:15 ./tl.1.go:18:15: make([]T, K) escapes to heap: ./tl.1.go:18:15: flow: {heap} = &{storage for make([]T, K)}: ./tl.1.go:18:15: from make([]T, K) (too large for stack) at ./tl.1.go:18:15 ./tl.1.go:12:14: make([]T, N) does not escape ./tl.1.go:15:15: make([]T, n) escapes to heap ./tl.1.go:18:15: make([]T, K) escapes to heap On Sunday, May 23, 2021 at 4:51:30 AM UTC-4 tapi...@gmail.com wrote: > In the following code, "make([]T, n)" is reported as escaped. > But does it really always escape at run time? > Does the report just mean "make([]T, n) possibly escapes to heap"? > > package main > > type T int > > const K = 1<<13 > const N = 1<<12 > var n = N > var i = n-1 > > func main() { > var r = make([]T, N) // make([]T, N) does not escape > println(r[i]) > > var r2 = make([]T, n) // make([]T, n) escapes to heap > println(r2[i]) > > var r3 = make([]T, K) // make([]T, K) escapes to heap > println(r3[i]) > } > -- 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/c649d34d-7d78-4646-a7d8-e0f286a65fbdn%40googlegroups.com.