1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Repeated malloc test.
16 var chatty
= flag
.Bool("v", false, "chatty")
19 var memstats runtime
.MemStats
23 runtime
.ReadMemStats(st
)
27 println(st
.Sys
, " system bytes for ", st
.Alloc
, " Go bytes")
37 runtime
.GC() // clean up garbage from init
38 runtime
.ReadMemStats(&memstats
) // first call can do some allocations
39 runtime
.MemProfileRate
= 0 // disable profiler
40 stacks
:= memstats
.Alloc
// ignore stacks
42 for i
:= 0; i
< 1<<7; i
++ {
43 for j
:= 1; j
<= 1<<22; j
<<= 1 {
44 if i
== 0 && *chatty
{
45 println("First alloc:", j
)
47 if a
:= memstats
.Alloc
- stacks
; a
!= 0 {
48 println("no allocations but stats report", a
, "bytes allocated")
51 b
:= runtime
.Alloc(uintptr(j
))
52 runtime
.ReadMemStats(&memstats
)
53 during
:= memstats
.Alloc
- stacks
55 runtime
.ReadMemStats(&memstats
)
56 if a
:= memstats
.Alloc
- stacks
; a
!= 0 {
57 println("allocated ", j
, ": wrong stats: during=", during
, " after=", a
, " (want 0)")
62 if i
%(1<<10) == 0 && *chatty
{
69 // runtime.frozen = true