[Rcpp-devel] Have I noticed memory management bug in RcppArmadillo or is this the intended behaviour?

Davor Cubranic cubranic at stat.ubc.ca
Sat Oct 29 01:38:51 CEST 2011


Instead of looking at Task Manager or Top, could you also look at the output 
of "gc(TRUE)" before and after running the microbenchmark? 

Or even use mallinfo for full details of memory allocations 
(http://rforge.net/mallinfo/files/, and there is a thread illustrating its use 
at http://thread.gmane.org/gmane.comp.lang.r.devel/28945).

Davor


On October 28, 2011 08:19:03 AM Dirk Eddelbuettel wrote:
> Slava,
> 
> Here is what I would call a reproducible example:  An empty function each
> for the R C API, for Rcpp and for RcppArmadillo being each called a
> million times:
> 
> R> require(inline)
> R> require(microbenchmark)
> R>
> R> fRcppArma <- cxxfunction(signature(), body='', plugin="RcppArmadillo")
> R>
> R> fRcpp <- cxxfunction(signature(), body='', plugin="Rcpp")
> R>
> R> fRC <- cfunction(signature(), body='')
> R>
> R> microbenchmark(fRcppArma, fRcpp, fRC, times=1e6)
> Unit: nanoseconds
>        expr min lq median uq   max
> 1       fRC  33 38     39 39 14297
> 2     fRcpp  34 40     42 43 17131
> 3 fRcppArma  36 41     42 43  8376
> R>
> 
> This suggests a possibly significant increase at the median of about three
> nanoseconds relative to barebones C API.
> 
> Your question was about memory, though.  So let's use our trusted littler
> tool and some glancing at htop in another console when running these
> one-liners:
> 
> $ r -linline -e'fRC <- cfunction(signature(), body=""); while(TRUE) fRC()'
> $ r -linline -e'fRcpp <- cfunction(signature(), body="", plugin="Rcpp");
> while(TRUE) fRcpp()' $ r -linline -e'fRcppArma <- cxxfunction(signature(),
> body="", plugin="RcppArmadillo"); while(TRUE) fRcppArma()'
> 
> 
> The results are
> 
> 
>      	      Virt     Res
> fRc  	      106M     36116	       stable, no increase
> fRcpp	      118M     42216	       fluctuates, but does not increase beyond
> 42200-ish fRcppArma     130M     47788	       stable
> 
> 
> The difference in code is the inclusion of the different headers, and
> static objects that may be defined there.   However, no run-time behaviour
> can be seen.
> 
> So if you see a leak, it may be in your code.
> 
> Hope this helps,  Dirk


More information about the Rcpp-devel mailing list