1 // $G $D/$F.go && $L $F.$A && ./$A.out
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Repeated malloc test.
16 var chatty = flag.Bool("v", false, "chatty")
21 runtime.UpdateMemStats()
22 if st := runtime.MemStats; oldsys < st.Sys {
25 println(st.Sys, " system bytes for ", st.Alloc, " Go bytes")
35 runtime.GC() // clean up garbage from init
36 runtime.UpdateMemStats() // first call can do some allocations
37 runtime.MemProfileRate = 0 // disable profiler
38 runtime.MemStats.Alloc = 0 // ignore stacks
40 for i := 0; i < 1<<7; i++ {
41 for j := 1; j <= 1<<22; j <<= 1 {
42 if i == 0 && *chatty {
43 println("First alloc:", j)
45 if a := runtime.MemStats.Alloc; a != 0 {
46 println("no allocations but stats report", a, "bytes allocated")
49 b := runtime.Alloc(uintptr(j))
50 runtime.UpdateMemStats()
51 during := runtime.MemStats.Alloc
53 runtime.UpdateMemStats()
54 if a := runtime.MemStats.Alloc; a != 0 {
55 println("allocated ", j, ": wrong stats: during=", during, " after=", a, " (want 0)")
60 if i%(1<<10) == 0 && *chatty {
67 // runtime.frozen = true