I found after b := make([]byte,4096000000)
, the allocated memory is virtual memory, I want to mark them as RES(physical memory usage as seen in top ), how to do this?
rand.Read(b)
is very slow.
I found after b := make([]byte,4096000000)
, the allocated memory is virtual memory, I want to mark them as RES(physical memory usage as seen in top ), how to do this?
rand.Read(b)
is very slow.
Use at least one byte in each page. For example,
package main
import (
"fmt"
"time"
)
func main() {
b := make([]byte, 2*1024*1024*1024)
fmt.Println(len(b))
pagesize := os.Getpagesize()
for i := 0; i < 60; i++ {
for j := 0; j < len(b); j += pagesize {
b[j] = 42
}
time.Sleep(1 * time.Second)
}
}
Output:
2147483648
top:
RES 2.1g