On Thu, Apr 13, 2017 at 8:33 PM, 刘桂祥 <liuguixiang...@gmail.com> wrote:
> // example.go
> package main
>
>
> import "runtime"
>
>
> type S struct{}
>
>
> func main() {
>  var stats runtime.MemStats
>
>
>  runtime.ReadMemStats(&stats)
>  println(stats.Mallocs)
>  var x S
>  runtime.ReadMemStats(&stats)
>  println(stats.Mallocs)
>  _ = *ref(x)
>  runtime.ReadMemStats(&stats)
>  println(stats.Mallocs)
> }
>
>
> func ref(z S) *S {
>  return &z
> }
>
> go build -gcflags '-N -l' example.go && ./example
> or
> go run -gcflags '-N -l' example.go
>
> results:
> ./example.go:21: &z escapes to heap
> ./example.go:20: moved to heap: z
> ./example.go:10: main &stats does not escape
> ./example.go:13: main &stats does not escape
> ./example.go:16: main &stats does not escape
> 61
> 61
> 61

That looks like the output from -gcflags="-m -l".  Are you really sure
you typed -N?  What version of Go are you using?

Ian

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