1 | module runtime |
2 | |
3 | fn C.sysconf(name int) i64 |
4 | |
5 | // nr_cpus returns the number of virtual CPU cores found on the system. |
6 | pub fn nr_cpus() int { |
7 | return int(C.sysconf(C._SC_NPROCESSORS_ONLN)) |
8 | } |
9 | |
10 | // total_memory returns total physical memory found on the system. |
11 | pub fn total_memory() usize { |
12 | page_size := usize(C.sysconf(C._SC_PAGESIZE)) |
13 | phys_pages := usize(C.sysconf(C._SC_PHYS_PAGES)) |
14 | return page_size * phys_pages |
15 | } |
16 | |
17 | // free_memory returns free physical memory found on the system. |
18 | pub fn free_memory() usize { |
19 | return free_memory_impl() |
20 | } |