I think I understand the principle, however with my best effort I cannot find a test case. Here I thought I'd be passing an arbitrarily large arma matrix to some function, but again the timing is not convincing (in fact, I had to stop the execution once with the dummy2 version),
using namespace Rcpp ; using namespace RcppArmadillo ; extern "C" { arma::mat dum1(arma::mat B) { return (B*38); } arma::mat dum2(const arma::mat& B) { return (B*38); } RCPP_FUNCTION_2(NumericMatrix, dummy1, NumericMatrix A, int N) { arma::mat B = Rcpp::as< arma::mat >( A ) ; return wrap(dum1(repmat(B, N, N))); } RCPP_FUNCTION_2(NumericMatrix, dummy2, NumericMatrix A, int N) { arma::mat B = Rcpp::as< arma::mat >( A ) ; return wrap(dum2(repmat(B, N, N))); } } } Regards, baptiste On 11 August 2010 19:21, Davor Cubranic <cubra...@stat.ubc.ca> wrote: > On August 11, 2010 02:48:23 am rom...@r-enthusiasts.com wrote: >> Le 10 août 2010 à 22:10, baptiste auguie > <baptiste.aug...@googlemail.com> a écrit : >> > OK, thanks. I have not been able to produce a minimal code that >> > would exhibit an improved performance using this >> > passing-by-reference idea. >> >> Hi, >> >> It would usually make a difference when copying the object that is >> passed by value is "expensive" to copy. Rcpp objects are very cheap >> to copy and both copies refer to the same actual data (the same >> SEXP). >> >> For internal code my recommendation would be to always use pass by >> reference and do an explicit call to clone when a real copy >> (different SEXP) is needed. > > In other words, if you were passing large arma::mat's, then const > references should make a real difference. > > Davor > _______________________________________________ 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