github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/sysinfo/memtotal_windows.go (about) 1 package sysinfo 2 3 import ( 4 "syscall" 5 "unsafe" 6 ) 7 8 // PhysicalMemoryBytes returns the total amount of host memory. 9 func PhysicalMemoryBytes() (uint64, error) { 10 // https://msdn.microsoft.com/en-us/library/windows/desktop/cc300158(v=vs.85).aspx 11 // http://stackoverflow.com/questions/30743070/query-total-physical-memory-in-windows-with-golang 12 mod := syscall.NewLazyDLL("kernel32.dll") 13 proc := mod.NewProc("GetPhysicallyInstalledSystemMemory") 14 var memkb uint64 15 16 ret, _, err := proc.Call(uintptr(unsafe.Pointer(&memkb))) 17 // return value TRUE(1) succeeds, FAILED(0) fails 18 if ret != 1 { 19 return 0, err 20 } 21 22 return memkb * 1024, nil 23 }