Skip to content

memory

miscellaneous · scripts/miscellaneous/memory.m

: memory ()
: [userdata, systemdata] = memory ()

Report how much memory Nexus and the system are using.

Called without outputs, a short table of the current figures is printed. With outputs nothing is printed and two structures are returned.

userdata describes the Nexus process:

MaxPossibleArrayBytes

Upper bound on the size of one array, counting physical memory and swap together. Allocating anything close to this will make the machine swap heavily and may destabilise it. Address-space fragmentation, which can lower the true limit on 32-bit systems, is not taken into account.

MemAvailableAllArrays

Memory available to Nexus in total, in bytes.

ram_available_all_arrays

Memory available in physical RAM alone, in bytes, with the same caveat about fragmentation.

MemUsedMATLAB
mem_used_nexus

Memory in use by this process, including swapped pages, in bytes. The first name exists for compatibility with scripts written for other systems.

ram_used_nexus

Physical memory in use by this process, in bytes.

systemdata describes the machine:

PhysicalMemory.Available
PhysicalMemory.Total

Free and installed physical memory, in bytes.

SystemMemory.Available
SystemMemory.Total

Free and installed memory including swap, in bytes.

VirtualAddressSpace.Available
VirtualAddressSpace.Total

Free and total virtual address space of the process, in bytes.

Example: print the table.

memory ()
⇒ 
System    RAM: 16294184 KiB,  swap: 2097148 KiB
Nexus     RAM:   214840 KiB,  virt: 1512344 KiB
Free      RAM:  9011720 KiB,  swap: 2097148 KiB
Available RAM: 11108868 KiB, total: 13206016 KiB

Example: pick out one figure.

[u, s] = memory ();
fprintf ("%.1f GiB of RAM free\n", s.PhysicalMemory.Available / 2^30);

This function is available on Linux and Windows. On other systems it issues a warning and returns nothing.