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 <javascript:>> 
> 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.
>
>
>> -- 
>> 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 golan...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/e3a947ed-1a42-4d17-991d-d29cc80685e0%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/e3a947ed-1a42-4d17-991d-d29cc80685e0%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/b66f0db6-575d-44eb-baf0-5a7d73997635%40googlegroups.com.

Reply via email to