tpq / peakRAM

[EXPERIMENTAL] An R package to monitor the peak RAM used by R expressions and functions
20 stars 1 forks source link

RAM used by C code? #2

Open tdhock opened 7 years ago

tdhock commented 7 years ago

Hey @tpq interesting package! It looks like you use gc() to track memory usage, right? I like the portability of your approach (I see from the CRAN check page https://cran.r-project.org/web/checks/check_results_peakRAM.html that it works on all systems).

But because you use gc() that means that any code that calls C and allocates memory outside of the R garbage collector will not be counted, right?

@analyticalmonk did something similar in https://github.com/analyticalmonk/Rperform but we ended up using the ps command line program to measure memory https://github.com/analyticalmonk/Rperform/blob/master/exec/rss.sh so we could count all memory that the R process is using (even outside of the garbage collector). one issue with this approach is that it only works on systems with the ps program.

tpq commented 7 years ago

Thanks for your interest, @tdhock. I must admit that I know little about how C allocates memory, but I have a feeling you're right. I had originally written this package for benchmarking my own Rcpp code, for which it seems to work quite well. As I understand it, Rcpp exposes all C++ objects to the R garbage collector via SEXP intermediaries.