[Rcpp-devel] RcppArmadillo matrix with writeable auxiliary memory

Dirk Eddelbuettel edd at debian.org
Tue Nov 26 04:27:57 CET 2013


Steven,

In a case like this I would try to set up a fist minimal working example
using just plain C++, and no R. Once that works, try it with R.

For Armadillo, the docs at http://arma.sourceforge.net/docs.html#Mat are your
best shot.  I presume you saw what it says about strict=true. Also, in 

   double* p = static_cast<double*>( malloc( 30*sizeof(double) ));
   arma::mat M(p, 3,10, false, true ); // this works nicely

you are going against the "Writing R Extensions" rule of mixing system
malloc/free with R.  That is generally a bad idea.

If your intent is to keep memory 'fixed' and outside of R, you can use
Bigmemory objects via external pointers (Rcpp::XPtr). This may be of
interest: http://gallery.rcpp.org/articles/using-bigmemory-with-rcpp/

That should extend to wrapping Armadillo around such memory. After all,
Armadillo behaves just _great_ with the R-allocated objects we pass back and
forth.

Hope this helps,  Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list