skeleton for testing purposes
This commit is contained in:
1 parent
8076b30e3f
commit
71e4f1294e
11 files changed
+273
No files matched your search
@@ -0,0 +1,44 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user