Re: [golang-dev] compiler optimization, when calling new function in a function?

101 views
Skip to first unread message

Ian Lance Taylor

unread,
Apr 24, 2018, 9:35:01 AM4/24/18
to xie cui, golang-dev
On Tue, Apr 24, 2018 at 1:12 AM, xie cui <cuiw...@gmail.com> wrote:
>
> func foo() {
> a := new(int)
> fmt.Println(*a)
> return
> }
>
> like this ,when calling new in the function, will it be optimazed as a
> stack allaction instead of a heap allaction?

Normally, yes. For cases where it really matters you can verify this
by compiling with the -m option (go build -gcflags=-m). That will
direct the compiler to print a debugging log of escape analysis
decisions.

Ian
Reply all
Reply to author
Forward
0 new messages