// example1.go
package main
import "runtime"
func main() {
m := new(runtime.MemStats)
runtime.ReadMemStats(m)
println(m.Alloc, m.Mallocs)
cap := 1024 * 1024 * 3
s := make([]byte, cap)
_ = s
runtime.ReadMemStats(m)
println(m.Alloc, m.Mallocs)
}
go run example1.go
32744 65
3178472 66
// example2.go
package main
import "runtime"
func main() {
m := new(runtime.MemStats)
runtime.ReadMemStats(m)
println(m.Alloc, m.Mallocs)
cap := 1024 * 1024 * 4
s := make([]byte, cap)
_ = s
runtime.ReadMemStats(m)
println(m.Alloc, m.Mallocs)
}
go run example2.go
32744 65
4228984 77
why it have 12 times mallocs ??
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.