package main

func main() {
    var m map[int]int

    {
        m = make(map[int]int)
    }

    _ = m
}

if I do this m will not escape just want to know what's the scope rule for 
escape ?  puzzled 
<http://www.baidu.com/link?url=ApC817U9uUoCFHhS_dqb5JzUWJQsslUUA6_TDv3LDZBJgaA-G2ZbRfWA-2cGajgU_MHmTiXVEouMmdPN53mMMXxYd1nvCWWJJvfu5Mmg4Ca>
 

在 2016年9月29日星期四 UTC+8上午1:39:09,Chris Manghane写道:
>
> In the first example, make does not escape the scope of the for statement. 
> In the second example, make is assigned to m, which is outside of the scope 
> of the for statement, which means the make operation escapes its scope and 
> subsequently, is heap allocated. If you want more information about why 
> something escapes, try compiling with -gcflags "-m -m" for an explanation 
> of the escape analysis information.
>
> On Wed, Sep 28, 2016 at 7:56 AM, 刘桂祥 <liuguix...@gmail.com <javascript:>> 
> wrote:
>
>> go 1.7
>>
>> 在 2016年9月28日星期三 UTC+8下午10:41:09,Dave Cheney写道:
>>
>>> Which version of Go?
>>>
>>> On Thursday, 29 September 2016 00:18:29 UTC+10, 刘桂祥 wrote:
>>>>
>>>> // example1.go
>>>> package main
>>>>
>>>>
>>>> func main() {
>>>>
>>>>     for i := 0; i < 2; i++ {
>>>>         m := make(map[int]int)                                         
>>>>                                                                            
>>>>  
>>>>                        
>>>>         m[1] = 100 
>>>>     }   
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>> main make(map[int]int) does not escape
>>>>
>>>>
>>>> // example2.go
>>>> package main
>>>>
>>>>
>>>> func main() {
>>>>     var m map[int]int
>>>>     for i := 0; i < 2; i++ {
>>>>         m = make(map[int]int)                                         
>>>>                                                                            
>>>>  
>>>>                        
>>>>         m[1] = 100 
>>>>     }   
>>>>
>>>>
>>>> }
>>>>
>>>>  make(map[int]int) escapes to heap    why ???
>>>>
>>>>
>>>> -- 
>> 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 <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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