Learn R Programming

BigDataStatMeth (version 2.0.3)

get_available_ram: Get available (free) system RAM

Description

Returns the amount of RAM currently available for allocation.

Usage

get_available_ram()

Arguments

Value

Numeric value with available RAM in gigabytes (GB)

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.

See Also

get_total_ram, can_allocate

Examples

Run this code
# \donttest{
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)
# }

Run the code above in your browser using DataLab