mirror of https://github.com/shirou/gopsutil
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.
40 lines
887 B
Go
40 lines
887 B
Go
// SPDX-License-Identifier: BSD-3-Clause
|
|
//go:build windows
|
|
|
|
package mem
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
// ExVirtualMemory represents Windows specific information
|
|
// https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex
|
|
type ExVirtualMemory struct {
|
|
VirtualTotal uint64 `json:"virtualTotal"`
|
|
VirtualAvail uint64 `json:"virtualAvail"`
|
|
}
|
|
|
|
type ExWindows struct{}
|
|
|
|
func NewExWindows() *ExWindows {
|
|
return &ExWindows{}
|
|
}
|
|
|
|
func (e *ExWindows) VirtualMemory() (*ExVirtualMemory, error) {
|
|
var memInfo memoryStatusEx
|
|
memInfo.cbSize = uint32(unsafe.Sizeof(memInfo))
|
|
mem, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memInfo)))
|
|
if mem == 0 {
|
|
return nil, windows.GetLastError()
|
|
}
|
|
|
|
ret := &ExVirtualMemory{
|
|
VirtualTotal: memInfo.ullTotalVirtual,
|
|
VirtualAvail: memInfo.ullAvailVirtual,
|
|
}
|
|
|
|
return ret, nil
|
|
}
|