runtime: delete UpdateMemStats, replace with ReadMemStats(&stats).

Unexports runtime.MemStats and rename MemStatsType to MemStats.
The new accessor requires passing a pointer to a user-allocated
MemStats structure.

Fixes #2572.

R=bradfitz, rsc, bradfitz, gustavo
CC=golang-dev, remy
https://golang.org/cl/5616072
This commit is contained in:
Rémy Oudompheng 2012-02-06 19:16:26 +01:00
parent 9c060b8d60
commit 842c906e2e
23 changed files with 129 additions and 105 deletions

View file

@ -10,20 +10,21 @@ import (
)
func TestGcSys(t *testing.T) {
memstats := new(runtime.MemStats)
runtime.GC()
runtime.UpdateMemStats()
sys := runtime.MemStats.Sys
runtime.ReadMemStats(memstats)
sys := memstats.Sys
for i := 0; i < 1000000; i++ {
workthegc()
}
// Should only be using a few MB.
runtime.UpdateMemStats()
if sys > runtime.MemStats.Sys {
runtime.ReadMemStats(memstats)
if sys > memstats.Sys {
sys = 0
} else {
sys = runtime.MemStats.Sys - sys
sys = memstats.Sys - sys
}
t.Logf("used %d extra bytes", sys)
if sys > 4<<20 {