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

Dirk Eddelbuettel edd at debian.org
Fri Oct 28 17:19:03 CEST 2011


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	

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list