mem_usage
result = mem_usage()
Input: no input · Output: result
What it is
Takes no arguments.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = mem_usage() | no input | profile_end —repl-diagnostics chapter | Returns this process's resident-set size right now, in bytes (a Num) — what THIS run has actually mapped in, not the machine's total memory (sysinfo()'s job). none on a platform this isn't implemented for (anything but Windows and Linux today). Call it before and after the code being compared and take the difference: the question "which of these two ways of computing the same result used more memory" that timing alone can't answer. See also profile_start/profile_end (repl-diagnostics chapter) for the same reading bundled with elapsed time into one clean before/after window, instead of two bare mem_usage() calls. |
Examples
No documentation example calls this form yet. The Concurrency chapter is where one belongs.
How it works
mem_usage() -- this process's resident-set size right now, in bytes. sysinfo()'s .total_memory is the MACHINE's memory; this is what THIS run has actually mapped in, the number that answers "which of these two ways of computing the same thing used more RAM" -- a question timing alone can't answer (a vectorized method can easily be faster AND build a much bigger intermediate array). Returns nothing on a platform this isn't implemented for (anything but Windows and Linux today) rather than a guess -- same convention as sysinfo()'s own optional fields. Call it before and after the code being measured and take the difference; RSS never shrinks from an ordinary garbage collection the way some runtimes' heap-size counters do, so a rising delta across back-to-back calls is a real signal, not GC noise. resource::current_rss_bytes is the one shared RSS reader (qu-cli's --profile/--max-memory watchdog uses the same function, not a second copy) -- see that module for the platform-by-platform implementation. profile_start()/ profile_end() wrap this same primitive into a clean before/after window with timing bundled in; reach for those instead of two bare mem_usage() calls when both numbers are wanted at once.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.