Hi  Chris:


          I am gopher from Beijing China . I am very like programing and adore 
the old hack culture . and NBA too!


        I am very happy in google groups and receive the answer so quickly. 
 


        go on practice programing and improve my badly english 


     

       question:  


       package main


func main() {

    var a []int


Label1:

    a = make([]int, 0, 2)

    _ = a

}


 could’t you give me an example that happens escape ?

在 2016年10月1日星期六 UTC+8上午12:19:17,Chris Manghane写道:
>
> Hmm, I'm not so sure if that's the rule. The rules are expressed in the 
> code in 
> https://github.com/golang/go/blob/master/src/cmd/compile/internal/gc/esc.go, 
> which is unlikely to make any significant changes in the near future. Those 
> rules aren't written in plain english, but we should not discourage any 
> attempts to do so.
>
> Chris
>
> On Thu, Sep 29, 2016 at 11:42 PM, 'Axel Wagner' via golang-nuts <
> [email protected] <javascript:>> wrote:
>
>> The only real rule is "when the compiler can prove, that it doesn't 
>> escape, it doesn't". There is no guarantee or fixed policy around escape 
>> analysis.
>> If you are convinced that something doesn't escape and that the compiler 
>> should be able to figure it out, you can try filing an issue about that 
>> with the code and output of -gcflags=-m.
>>  
>>
> On Fri, Sep 30, 2016 at 5:20 AM, 刘桂祥 <[email protected] <javascript:>> 
>> wrote:
>>
>>> 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, 刘桂祥 <[email protected]> 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 [email protected].
>>>>> 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 [email protected] <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 [email protected] <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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to