On Friday, January 27, 2017 at 4:05:03 AM UTC+8, Ian Lance Taylor wrote:
>
> On Thu, Jan 26, 2017 at 11:10 AM, T L <tapi...@gmail.com <javascript:>> 
> wrote: 
> > 
> > I still don't understand what are implicit memory allocations, could you 
> > make an explanation? 
>
> An example of an implicit memory allocation: 
>
> var globalVar *int 
> func f() { 
>     var i int 
>     globalVar = &i 
> } 
>
> Another one: 
>
> var globalVar interface{} 
> func f() { 
>     globalVar = 0 
> } 
>
> Ian 
>

It looks -+ doesn't think the second one is implicit memory allocation.
"-m" really think it is an "escapes to heap".

So I am still not very clear on what is implicit memory allocation.
It looks the output of -+ is hard to predict.
For example, in the following program, f1 and f3 are reported as implicit 
memory allocation, but f2 and f4 are not:

package main

import "fmt"

var globalVar1 *int
func f1() {
    var i int
    globalVar1 = &i
}

var globalVar2 interface{}
func f2() {
    globalVar2 = 0
}

func f3() {
    a := 2
    fmt.Println(&a)
}

func f4() {
    c := make(chan int, 10)
    c <- 1
    
    go func() {
        <-c
    }()
}

func main() {
}




 

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to