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.
18 var chatty = flag.Bool("v", false, "chatty")
24 runtime.UpdateMemStats()
25 if f := runtime.MemStats.Sys; footprint < f {
28 println("Footprint", footprint, " for ", allocated)
37 // Prime the data structures by allocating one of
38 // each block in order. After this, there should be
39 // little reason to ask for more memory from the OS.
41 for i := 0; i < 16; i++ {
42 b := runtime.Alloc(1 << uint(i))
45 for i := uintptr(0); i < 256; i++ {
46 b := runtime.Alloc(i << 12)
51 func memset(b *byte, c byte, n uintptr) {
53 for i := uintptr(0); i < np; i++ {
54 *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(b)) + i)) = c
61 var blocks [1]struct {
65 for i := 0; i < 1<<10; i++ {
66 if i%(1<<10) == 0 && *chatty {
69 b := rand.Int() % len(blocks)
70 if blocks[b].base != nil {
71 // println("Free", blocks[b].siz, blocks[b].base)
72 runtime.Free(blocks[b].base)
74 allocated -= uint64(blocks[b].siz)
77 siz := uintptr(rand.Int() >> (11 + rand.Uint32()%20))
78 base := runtime.Alloc(siz)
79 // ptr := uintptr(syscall.BytePtr(base))+uintptr(siz/2)
80 // obj, size, ref, ok := allocator.find(ptr)
81 // if obj != base || *ref != 0 || !ok {
82 // println("find", siz, obj, ref, ok)
87 allocated += uint64(siz)
88 // println("Alloc", siz, base)
89 memset(base, 0xbb, siz)