get_available_ram: Get available (free) system RAM

View source: R/RcppExports.R

get_available_ramR Documentation

Get available (free) system RAM

Description

Returns the amount of RAM currently available for allocation.

Usage

get_available_ram()

Details

This function returns the RAM that can be allocated without swapping. The value changes dynamically as processes allocate and free memory.

Important notes:

  • Value can change rapidly; don't cache it

  • On Linux, uses MemAvailable (more accurate than MemFree)

  • Includes memory that can be reclaimed from caches

  • Actual allocatable memory may be slightly less

Use case: Check available RAM before loading large datasets into memory.

Value

Numeric value with available RAM in gigabytes (GB)

See Also

get_total_ram, can_allocate

Examples


available <- get_available_ram()
cat("Available RAM:", round(available, 2), "GB\n")

# Use it to decide how much data to load
fn <- tempfile(fileext = ".h5")
X  <- hdf5_create_matrix(fn, "data/M",
                          data = matrix(rnorm(1000), 100, 10))

size_gb <- prod(dim(X)) * 8 / 1e9
if (get_available_ram() > size_gb * 1.2) {
  mat <- as.matrix(X)
} else {
  mat <- X[1:50, ]
}

hdf5_close_all()
unlink(fn)



BigDataStatMeth documentation built on May 15, 2026, 1:07 a.m.