You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gopsutil/mem_windows.go

49 lines
1.0 KiB
Go

11 years ago
// +build windows
package gopsutil
11 years ago
import (
"syscall"
"unsafe"
)
var (
procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx")
)
type MEMORYSTATUSEX struct {
cbSize uint32
dwMemoryLoad uint32
ullTotalPhys uint64 // in bytes
ullAvailPhys uint64
ullTotalPageFile uint64
ullAvailPageFile uint64
ullTotalVirtual uint64
ullAvailVirtual uint64
ullAvailExtendedVirtual uint64
}
func VirtualMemory() (*VirtualMemoryStat, error) {
var memInfo MEMORYSTATUSEX
memInfo.cbSize = uint32(unsafe.Sizeof(memInfo))
mem, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memInfo)))
if mem == 0 {
return nil, syscall.GetLastError()
}
ret := &VirtualMemoryStat{
Total: memInfo.ullTotalPhys,
Available: memInfo.ullAvailPhys,
UsedPercent: float64(memInfo.dwMemoryLoad),
}
ret.Used = ret.Total - ret.Available
11 years ago
return ret, nil
}
func SwapMemory() (*SwapMemoryStat, error) {
ret := &SwapMemoryStat{}
11 years ago
return ret, nil
}