FAQ
In the following code.

s := Struct{}
s.SomePointerReceiverMethod()

Will go allocate s on the stack? or on the heap? Can the escape analysis
tell whether or not the address of s remains stored somewhere even after
SomePointerReceiverMethod() returns?

--
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/groups/opt_out.

Search Discussions

  • Chris dollin at Mar 20, 2013 at 8:46 pm

    On 20 March 2013 20:42, Travis Keep wrote:
    In the following code.

    s := Struct{}
    s.SomePointerReceiverMethod()

    Will go allocate s on the stack? or on the heap?
    It depends on the usage of s both within SomeEtc
    and following the call (and how smart the analyser is).
    Can the escape analysis
    tell whether or not the address of s remains stored somewhere even after
    SomePointerReceiverMethod() returns?
    There are cases where it can tell that the address
    /doesn't/ remain stored. If it can't be sure that the
    address doesn't escape, it must treat it as if it does.

    Chris

    --
    Chris "allusive" Dollin

    --
    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/groups/opt_out.
  • Rob Pike at Mar 20, 2013 at 8:46 pm

    On Wed, Mar 20, 2013 at 1:42 PM, Travis Keep wrote:
    In the following code.

    s := Struct{}
    s.SomePointerReceiverMethod()

    Will go allocate s on the stack? or on the heap? Can the escape analysis
    tell whether or not the address of s remains stored somewhere even after
    SomePointerReceiverMethod() returns?
    Either the stack or the heap. The escape analysis might be able to
    tell. The answers to all these questions might change as your program
    and the compilers evolve.

    Let the compiler work it out for you. Don't overthink it.

    -rob

    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 20, '13 at 8:46p
activeMar 20, '13 at 8:47p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase