| 1 | module runtime |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | @[typedef] |
| 6 | pub struct C.MEMORYSTATUS { |
| 7 | dwTotalPhys usize |
| 8 | dwAvailPhys usize |
| 9 | } |
| 10 | |
| 11 | fn C.GlobalMemoryStatus(&C.MEMORYSTATUS) |
| 12 | |
| 13 | // nr_cpus returns the number of virtual CPU cores found on the system. |
| 14 | pub 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. |
| 25 | pub 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. |
| 32 | pub fn free_memory() !usize { |
| 33 | memory_status := C.MEMORYSTATUS{} |
| 34 | C.GlobalMemoryStatus(&memory_status) |
| 35 | return memory_status.dwAvailPhys |
| 36 | } |
| 37 | |