[R] memory use without running gc()

Johann Hibschman jhibschman at gmail.com
Tue Aug 10 16:26:12 CEST 2010


Allan Engelhardt <allane at cybaea.com> writes:

> ### Method 2
> ## Setup
> file <- paste("/proc", Sys.getpid(), "stat", sep = "/")
> what <- vector("list", 44); what[[23]] <- integer(0)
> ## In your logging routine
> vsz <- scan(file, what = what, quiet = TRUE)[[23]]/1024
> cat("Virtual size: ", vsz, "\n", sep = "")

[...]

> The scan method should be plenty fast.  Change as appropriate if your
> definition of memory is different from virtual size.

Thanks, that works well.  I'm on an older kernel (2.6.18), so I only
have 42 entries in /proc/pid/stat, but VSZ is still in position 23.

Looking at the proc man page also shows /proc/[pid]/statm, which
collects some of the memory information, but requires me to know what
the page size is to make sense of it.

Gegards,
Johann



More information about the R-help mailing list