BlueGit

timfa bluegit

Files

bluegit / internal / runnercfg / hardware_windows.go

hardware_windows.go

hardware_windows.go 872 B Download Raw
1//go:build windows
2
3package runnercfg
4
5import (
6 "unsafe"
7
8 "golang.org/x/sys/windows"
9)
10
11type memoryStatusEx struct {
12 Length uint32
13 MemoryLoad uint32
14 TotalPhys uint64
15 AvailPhys uint64
16 TotalPageFile uint64
17 AvailPageFile uint64
18 TotalVirtual uint64
19 AvailVirtual uint64
20 AvailExtendedVirtual uint64
21}
22
23var (
24 modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
25 procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx")
26)
27
28// detectMemory leest het fysieke werkgeheugen via GlobalMemoryStatusEx, in MiB.
29func detectMemory() int {
30 var mem memoryStatusEx
31 mem.Length = uint32(unsafe.Sizeof(mem))
32 r1, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&mem)))
33 if r1 == 0 || mem.TotalPhys == 0 {
34 return 0
35 }
36 return int(mem.TotalPhys / 1024 / 1024)
37}