On Tue, Nov 1, 2011 at 9:11 PM, <rcpp-devel-requ...@r-forge.wu-wien.ac.at> wrote: > >> .Call("modify", m) >> m > [,1] [,2] [,3] [,4] [,5] > [1,] 1 3 5 7 9 > [2,] 2 4 6 8 10 > > > It didn't segfault, but the memory in R process didn't change as you see, > although the matrix in armadillo code doubled. Which means that > NumericMatrix copied memory from R process and passed a pointer to > armadillo.
3 quick points: 1: For the NumericMatrix->arma, you can use an advanced constructor to get the behavior that you desire. http://arma.sourceforge.net/docs.html#Mat -- you'll want copy_aux_mem = false. 2: Are you actually doing matrix math? If you're just doing simple element-by-element arithmetic, you might get just as good performance with a simple loop or iterator. You might try this first to understand the R/C++ process, and *then* move to using Armadillo :) 3: For completeness, note that "Rcpp::NumericMatrix r_m(clone(mem));" *forces* a copy, thus restoring R's "no side-effects" semantics. -Christian -- A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama! _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel