Files
RealConn/mem_windows.go
2026-11-03 17:54:17 -06:00

34 lines
798 B
Go

//go:build windows
package main
import (
"syscall"
"unsafe"
)
type memoryStatusEx struct {
Length uint32
MemoryLoad uint32
TotalPhys uint64
AvailPhys uint64
TotalPageFile uint64
AvailPageFile uint64
TotalVirtual uint64
AvailVirtual uint64
AvailExtendedVirtual uint64
}
var procGlobalMemoryStatusEx = syscall.NewLazyDLL("kernel32.dll").NewProc("GlobalMemoryStatusEx")
// hostMemory devuelve memoria disponible y total del host en bytes.
func hostMemory() (avail, total uint64, ok bool) {
var m memoryStatusEx
m.Length = uint32(unsafe.Sizeof(m))
r, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&m)))
if r == 0 {
return 0, 0, false
}
return m.AvailPhys, m.TotalPhys, m.TotalPhys > 0
}