-gcflags="-m -m" will make the compiler print out its escape analysis 
choices. This might be easier than instrumenting your code, which might 
affect the escape analysis decisions.

On Monday, 3 October 2016 13:48:47 UTC+11, 刘桂祥 wrote:
>
>   Yes  you are right . thanks a lot and I try more debug info and have 
> looked that:
>
>
> func main() {
>     println("debug")
>     a := interface{}(100)
>     println(&a, a)
>     b := fmt.Sprint(a)
>     println("debug1", b, &b, Pointer(*((*uintptr)(Pointer(&b)))), *((*int
> )(Pointer(uintptr(Pointer(&b)) + 8))))
> }
>
> and add debug info to runtime/mallocgc.go file
> here is the output:
>
> debug
> mallocgc: 8
> mallocgc return2: 0xc20800a220
> 0xc208039f68 (0xa00a0,0xc20800a220)
> mallocgc: 3
> mallocgc return2: 0xc20800a230
> debug1 100 0xc208039f48 0xc20800a230 3
>
> 在 2016年10月3日星期一 UTC+8上午9:47:18,Dave Cheney写道:
>>
>> On Monday, 3 October 2016 12:39:34 UTC+11, 刘桂祥  wrote: 
>> > package main 
>> > 
>> > 
>> > import ( 
>> >     "fmt" 
>> > ) 
>> > func main() { 
>> >     a := interface{}(100) 
>> >     println(&a, a) 
>> >     fmt.Sprint(a) 
>> > } 
>> > 
>> > 
>> > go run x.go  the output: 
>> > 
>> > 
>> > 0xc42003bf18 (0x89040,0xc42000a2c0) 
>> > 
>> > 
>> > 
>> > I just want to ask 0xc42000a2c0 as the a (interface{}) 's data pointer 
>> is point to where ? heap ? 
>>
>> It is on the heap, the value escapes when passed to fmt,Sprint 
>>
>> > 
>> > also I test this: 
>> > 
>> > 
>> > func BenchmarkFmtEscap3(b *testing.B) { 
>> >     b.ReportAllocs() 
>> > 
>> > 
>> >     for i := 0; i < b.N; i++ { 
>> >         a := interface{}(100) 
>> >         fmt.Sprint(a) 
>> >     } 
>> > } 
>> > 
>> > 
>> > BenchmarkFmtEscap3-4            10000000               141 
>> ns/op              16 B/op       2 allocs/op 
>> > 
>> > 
>> > 
>> > why is 2 allocs and 16bytes ?? 
>>
>> One for a, which escapes to the heap when passed to fmt.Sprint, and one 
>> for the value returned from fmt,Sprint 
>>
>>

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