-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit fixes #1588. Thank you!
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
//go:build windows | ||
|
||
package mem | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
// ExWindows represents Windows specific information | ||
// https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex | ||
type ExWindows struct { | ||
Check failure on line 14 in mem/ex_windows.go GitHub Actions / test (1.21.7, windows-2022)
Check failure on line 14 in mem/ex_windows.go GitHub Actions / test (1.22.0, windows-2022)
Check failure on line 14 in mem/ex_windows.go GitHub Actions / build_test_v3 (1.21.7)
Check failure on line 14 in mem/ex_windows.go GitHub Actions / build_test_v3 (1.22.0)
Check failure on line 14 in mem/ex_windows.go GitHub Actions / test (1.21.7, windows-2022)
Check failure on line 14 in mem/ex_windows.go GitHub Actions / test (1.21.7, windows-2019)
Check failure on line 14 in mem/ex_windows.go GitHub Actions / test (1.22.0, windows-2022)
Check failure on line 14 in mem/ex_windows.go GitHub Actions / test (1.22.0, windows-2019)
Check failure on line 14 in mem/ex_windows.go GitHub Actions / test (1.22.0, windows-2019)
Check failure on line 14 in mem/ex_windows.go GitHub Actions / test (1.21.7, windows-2019)
Check failure on line 14 in mem/ex_windows.go GitHub Actions / build_test_v3 (1.21.7)
|
||
VirtualTotal uint64 `json:"virtualTotal"` | ||
VirtualAvail uint64 `json:"virtualAvail"` | ||
} | ||
|
||
type ExWindows struct{} | ||
Check failure on line 19 in mem/ex_windows.go GitHub Actions / test (1.21.7, windows-2022)
Check failure on line 19 in mem/ex_windows.go GitHub Actions / test (1.22.0, windows-2022)
Check failure on line 19 in mem/ex_windows.go GitHub Actions / build_test_v3 (1.21.7)
Check failure on line 19 in mem/ex_windows.go GitHub Actions / build_test_v3 (1.22.0)
Check failure on line 19 in mem/ex_windows.go GitHub Actions / test (1.21.7, windows-2022)
Check failure on line 19 in mem/ex_windows.go GitHub Actions / test (1.21.7, windows-2019)
Check failure on line 19 in mem/ex_windows.go GitHub Actions / test (1.22.0, windows-2022)
Check failure on line 19 in mem/ex_windows.go GitHub Actions / test (1.22.0, windows-2019)
Check failure on line 19 in mem/ex_windows.go GitHub Actions / test (1.22.0, windows-2019)
Check failure on line 19 in mem/ex_windows.go GitHub Actions / test (1.21.7, windows-2019)
Check failure on line 19 in mem/ex_windows.go GitHub Actions / build_test_v3 (1.21.7)
|
||
|
||
func NewExWindows() *ExWindows { | ||
return &ExWindows{} | ||
} | ||
|
||
func (e *ExWindows) VirtualMemory() (*ExWindows, 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 := &ExWindows{ | ||
VirtualTotal: memInfo.ullTotalVirtual, | ||
VirtualAvail: memInfo.ullAvailVirtual, | ||
} | ||
|
||
return ret, nil | ||
} |