v / vlib / runtime / runtime_windows.c.v
36 lines · 30 sloc · 828 bytes · 5d4e89f8883f3f6fcc43d986297142402f4a9c71
Raw
1module runtime
2
3import os
4
5@[typedef]
6pub struct C.MEMORYSTATUS {
7 dwTotalPhys usize
8 dwAvailPhys usize
9}
10
11fn C.GlobalMemoryStatus(&C.MEMORYSTATUS)
12
13// nr_cpus returns the number of virtual CPU cores found on the system.
14pub fn nr_cpus() int {
15 sinfo := C.SYSTEM_INFO{}
16 C.GetSystemInfo(&sinfo)
17 mut nr := int(sinfo.dwNumberOfProcessors)
18 if nr == 0 {
19 nr = os.getenv('NUMBER_OF_PROCESSORS').int()
20 }
21 return nr
22}
23
24// total_memory returns total physical memory found on the system.
25pub fn total_memory() !usize {
26 memory_status := C.MEMORYSTATUS{}
27 C.GlobalMemoryStatus(&memory_status)
28 return memory_status.dwTotalPhys
29}
30
31// free_memory returns free physical memory found on the system.
32pub fn free_memory() !usize {
33 memory_status := C.MEMORYSTATUS{}
34 C.GlobalMemoryStatus(&memory_status)
35 return memory_status.dwAvailPhys
36}
37