How to get full memory / RAM in GO?

How can I get the total amount of memory / RAM connected to the system in Go? I want to use native code only if possible. I found a library that wraps the linux sysinfo command. Is there a more elegant way?

+6
source share
2 answers

Besides runtime.MemStats, you can use gosigar to monitor system memory.

+6
source

cgo and linux solution

package main // #include <unistd.h> import "C" func main() { println(C.sysconf(C._SC_PHYS_PAGES)*C.sysconf(C._SC_PAGE_SIZE), " bytes") } 
+4
source

Source: https://habr.com/ru/post/986466/


All Articles