Skip to content
CryoCryo home
Stdlibprocess

memory

import std::process::memory; · source

The machine's physical memory: how much it has, and how much is still available to a program that starts now. What one child used at its peak is ExitStatus.peak_memory_bytes.

import std::process::memory::{ SystemMemory };

const memory: SystemMemory = SystemMemory::query()?;
const spare_megabytes: u64 = memory.available_bytes() / 1048576;

Types

SystemMemory

type struct SystemMemory {
    private total:        u64;
    private available:    u64;
    private committed:    u64;
    private commit_limit: u64;
}

query() reads the figures once: MemTotal and MemAvailable from /proc/meminfo on Linux, GlobalMemoryStatusEx on Windows. On Linux it fails with the error reading the file gave, or InvalidData when either line is missing or not a number. total_bytes() is the physical memory installed; available_bytes() is what a program could still be given without the system paging anything out.

Constructors

static query() -> Result<SystemMemory, IoError>;

Read the machine's memory now: MemTotal, MemAvailable, Committed_AS and CommitLimit from /proc/meminfo on Linux, GlobalMemoryStatusEx and GetPerformanceInfo on Windows. Fails with the error reading /proc/meminfo gave, or InvalidData when any of those lines is missing or not a number.

static query() -> Result<SystemMemory, IoError>;

Read the machine's memory now: the total and available physical memory GlobalMemoryStatusEx reports, and the commit charge and its limit GetPerformanceInfo reports (/proc/meminfo on Linux). Fails with the system's error when either call fails.

Methods

total_bytes(&this) -> u64;

The physical memory installed, in bytes.

available_bytes(&this) -> u64;

The physical memory a program could still be given without the system paging anything out, in bytes.

committed_bytes(&this) -> u64;

The memory the system has promised to every running process, in bytes: what they have allocated, whether or not they have touched it yet. Windows calls it the commit charge; it counts against physical memory and the page file together, and an allocation that would take it past commit_limit_bytes fails. On Linux it is Committed_AS, which may exceed the limit, since Linux promises more than it has unless told not to overcommit.

commit_limit_bytes(&this) -> u64;

The most memory the system will promise, in bytes: physical memory and the page file (Windows), or the limit Linux enforces when it is told not to overcommit (CommitLimit).