escapes to heap,use "go tool compile -m".

在 2019年8月15日星期四 UTC+8下午12:06:20,Gergely Födémesi写道:
>
>
>
> On Thu, Aug 15, 2019, 05:19 sandao <yiren...@gmail.com <javascript:>> 
> wrote:
>
>> In my opinion, the slice which "as"  point to, is all allocated on the 
>> heap in two case . so, I think the mark time should not be so different. 
>> Can you tell me more details for you answer(when as is allocated on the 
>> stack, gc has a smaller task.)?
>>
>> 在 2019年8月15日星期四 UTC+8上午11:02:46,Gergely Födémesi写道:
>>>
>>> .On Wed, Aug 14, 2019, 17:56 sandao <yiren...@gmail.com> wrote:
>>>
>>>> type A struct {
>>>>         a int
>>>> }
>>>>
>>>> func gen() []*A {
>>>>         r := make([]*A, 1000000)
>>>>         for i := 0; i < len(r); i++ {
>>>>                 r[i] = &A{i}
>>>>         }
>>>>         return r
>>>> }
>>>>
>>>> //var as []*A = gen()
>>>>
>>>> func main() {
>>>>         go func() {
>>>>                 err := http.ListenAndServe(":8034", nil)
>>>>                 if err != nil {
>>>>                         //fmt.Printf("ListenAndServe:%s\n", err)
>>>>                 }
>>>>         }()
>>>>         var as []*A = gen()
>>>>         fmt.Println(as[0])
>>>>         time.Sleep(100 * time.Second)
>>>> }
>>>>
>>>> when debug gc:
>>>> 1)    if the "var as []*A = gen()"  is in main , the debug info is 
>>>> :  gc 4 @2.757s 0%: 0.049+0.59+0.025 ms clock, 2.3+0/0.54/0.28+1.2 ms 
>>>> cpu, 16->16->0 MB, 31 MB goal, 48 P (forced)
>>>> 2)    if the "var as []*A = gen()"  is not in main, the debug info 
>>>> is: gc 9 @7.172s 0%: 0.077+25+0.020 ms clock, 3.7+0/24/0.73+0.99 ms 
>>>> cpu, 16->16->15 MB, 31 MB goal, 48 P (forced)
>>>>
>>>> Anybody konw why the mark time (red numbers) is so different?    
>>>>
>>>
>>> when as is allocated on the stack, gc has a smaller task.
>>>
>>
> see for yourself what the compiler says about that decision:
> https://golang.org/cmd/compile/
> you'll need -m 
>
>  you can also use pprof to check your assumptions.
>
> (there isn't any computer near me currently)
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e14e140a-12c6-420e-a52a-4c47cc838502%40googlegroups.com.

Reply via email to