1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/runtime/runtime_windows.c.v

43 lines
918 B
V

module runtime
import os
[typedef]
struct C.SYSTEM_INFO {
dwNumberOfProcessors u32
}
[typedef]
struct C.MEMORYSTATUS {
dwTotalPhys usize
dwAvailPhys usize
}
fn C.GetSystemInfo(&C.SYSTEM_INFO)
fn C.GlobalMemoryStatus(&C.MEMORYSTATUS)
// nr_cpus returns the number of virtual CPU cores found on the system.
pub fn nr_cpus() int {
sinfo := C.SYSTEM_INFO{}
C.GetSystemInfo(&sinfo)
mut nr := int(sinfo.dwNumberOfProcessors)
if nr == 0 {
nr = os.getenv('NUMBER_OF_PROCESSORS').int()
}
return nr
}
// total_memory returns total physical memory found on the system.
pub fn total_memory() usize {
memory_status := C.MEMORYSTATUS{}
C.GlobalMemoryStatus(&memory_status)
return memory_status.dwTotalPhys
}
// free_memory returns free physical memory found on the system.
pub fn free_memory() usize {
memory_status := C.MEMORYSTATUS{}
C.GlobalMemoryStatus(&memory_status)
return memory_status.dwAvailPhys
}