45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package system_check
|
|
|
|
import (
|
|
"log"
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
type memoryStatusEx struct {
|
|
/*
|
|
* Struct for storing memory status information.
|
|
*
|
|
* It gets populated via syscall.
|
|
*/
|
|
dwLength uint32
|
|
dwMemoryLoad uint32
|
|
ullTotalPhys uint64
|
|
ullAvailPhys uint64
|
|
ullTotalPageFile uint64
|
|
ullAvailPageFile uint64
|
|
ullTotalVirtual uint64
|
|
ullAvailVirtual uint64
|
|
ullAvailExtendedVirtual uint64
|
|
}
|
|
|
|
func getWinRamInfo(procGlobalMemoryStatusEx *windows.LazyProc) MemoryInformation {
|
|
var mem memoryStatusEx
|
|
|
|
// * Windows requires the dwLength field to be set to the struct's size
|
|
// * before execution so it knows which OS struct version is being used.
|
|
mem.dwLength = uint32(unsafe.Sizeof(mem))
|
|
|
|
ret, _, err := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&mem))) // exec syscall
|
|
|
|
if ret == 0 { // winapi syscalls return 0 on failure
|
|
log.Fatalf("GlobalMemoryStatusEx failed: %v", err)
|
|
}
|
|
|
|
return MemoryInformation{
|
|
SystemMemory: mem.ullTotalPhys,
|
|
AvailableMemory: mem.ullAvailPhys,
|
|
}
|
|
}
|