| get_available_ram | R Documentation |
Returns the amount of RAM currently available for allocation.
get_available_ram()
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.
Numeric value with available RAM in gigabytes (GB)
get_total_ram, can_allocate
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.