Hi, there is no such thing as "possibly escaping". The compiler needs to decide whether to emit the code to reserve stack space for a variable or whether to emit the code to allocate heap-space. That's a binary choice, it will always do one or the other.
So, yes, `make([]T, n)` in this example always escapes. I assume the heuristic marks it as escaping because `n` is a non-local variable, so it doesn't prove that `n` is effectively constant. It might even just mark every `make` with a `var` argument as escaping. On Sun, May 23, 2021 at 10:51 AM tapi...@gmail.com <tapir....@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/0ef15402-2e71-4522-bf67-26f766da55e5n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/0ef15402-2e71-4522-bf67-26f766da55e5n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAEkBMfEpnvpQpUcNpA_VFvRjjHZC8TsnfpanFbTP%3DKUVcarZWw%40mail.gmail.com.