Selaa lähdekoodia

修复10.8的代码,使Go1.5.1能够运行

ArkBriar 10 vuotta sitten
vanhempi
commit
be2cea6c54
1 muutettua tiedostoa jossa 6 lisäystä ja 2 poistoa
  1. 6 2
      eBook/10.8.md

+ 6 - 2
eBook/10.8.md

@@ -7,7 +7,11 @@ Go 开发者不需要写代码来释放程序中不再使用的变量和结构
 如果想知道当前的内存状态,可以使用:
 
 ```go
-fmt.Printf("%d\n", runtime.MemStats.Alloc/1024)
+// fmt.Printf("%d\n", runtime.MemStats.Alloc/1024)
+// 此处代码在 Go 1.5.1下不再有效,更正为
+var m runtime.MemStats
+runtime.ReadMemStats(&m)
+fmt.Printf("%d Kb\n", m.Alloc / 1024)
 ```
 
 上面的程序会给出已分配内存的总量,单位是 Kb。进一步的测量参考 [文档页面](http://golang.org/pkg/runtime/#MemStatsType)。
@@ -30,4 +34,4 @@ runtime.SetFinalizer(obj, func(obj *typeObj))
 
 - [目录](directory.md)
 - 上一节:[类型的 String() 方法和格式化描述符](10.7.md)
-- 下一章:[接口(Interfaces)与反射(reflection)](11.0.md)
+- 下一章:[接口(Interfaces)与反射(reflection)](11.0.md)