|
|
@ -4,7 +4,6 @@ package mem
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"encoding/binary"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"unsafe"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
|
|
|
@ -13,17 +12,10 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func getHwMemsize() (uint64, error) {
|
|
|
|
func getHwMemsize() (uint64, error) {
|
|
|
|
totalString, err := unix.Sysctl("hw.memsize")
|
|
|
|
total, err := unix.SysctlUint64("hw.memsize")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// unix.sysctl() helpfully assumes the result is a null-terminated string and
|
|
|
|
|
|
|
|
// removes the last byte of the result if it's 0 :/
|
|
|
|
|
|
|
|
totalString += "\x00"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total := uint64(binary.LittleEndian.Uint64([]byte(totalString)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return total, nil
|
|
|
|
return total, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|