On Sun, May 23, 2021 at 11:09 AM tapi...@gmail.com <tapir....@gmail.com>
wrote:

> It also escapes if `n` is a local variable.
>
> From the code, it looks, if the capacity of the maked slice is larger than
> 1<<12, then the slice is allocated on heap.
>

Seems possible.

Is there a possibility that, in the "make" implementation, different
> routines are chosen by different capacity arguments?
>

It's possible (but I don't think so), but not insofar as it would impact
whether things end up on the stack or the heap.


>
> On Sunday, May 23, 2021 at 5:03:02 AM UTC-4 axel.wa...@googlemail.com
> wrote:
>
>> 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 <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...@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/a44f78ab-2c10-475d-aeeb-1eef8cb8e412n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/a44f78ab-2c10-475d-aeeb-1eef8cb8e412n%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/CAEkBMfFYtvu_X2mjTibbJ5gkY7kU5-atzKo2nhDT74vzYcK3Rg%40mail.gmail.com.

Reply via email to