mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
runtime: add new functions total_memory/0 and free_memory/0 (#18499)
This commit is contained in:
@@ -7,7 +7,14 @@ 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 {
|
||||
@@ -19,3 +26,17 @@ pub fn nr_cpus() 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user