Исходники и презентации
This commit is contained in:
22
lessons/slices_and_arrays/collection_optimization/main.go
Normal file
22
lessons/slices_and_arrays/collection_optimization/main.go
Normal file
@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func printAllocs() {
|
||||
var m runtime.MemStats
|
||||
runtime.ReadMemStats(&m)
|
||||
fmt.Printf("%d MB\n", m.Alloc/1024/1024)
|
||||
}
|
||||
|
||||
func main() {
|
||||
data := make([]byte, 1<<31)
|
||||
|
||||
printAllocs()
|
||||
runtime.GC()
|
||||
printAllocs()
|
||||
|
||||
fmt.Println(len(data))
|
||||
}
|
||||
Reference in New Issue
Block a user