1

As highlighted by e.g. this post, matrices can be passed to an arma::mat object by reference:

// [[Rcpp::export]]
void arma_test_ref( arma::mat& x){}

// [[Rcpp::export]]
void arma_test_const_ref( const arma::mat& x){}

Which other classes foreign to R allow objects to be passed by reference? I am thinking in particular of Armadillo classes like arma::vec, arma::spmat, arma::Mat<int> etc., but am also curious about classes outside Armadillo. There appears to be no list clarifying the issue in the documentation.

And as a supplementary question: does the choice of passing objects to arma::mat by reference or by value affect what the object looks like? Are they stored differently in memory or do they vary in any other regard that may affect the efficiency of their use in the C++ code?

Chr
  • 1,017
  • 1
  • 8
  • 29
  • 2
    It's a bit of a confusing (for C++ programmers new to R) topic but it is actually _all the same_ as there is only one interface: `SEXP .Call("yourfunction", SEXP, SEXP, SEXP, ...)` so _everything_ happens as pointers to S Expressions. Read up on Rcpp, it is covered in a few places, there are benchmarks etc... – Dirk Eddelbuettel Sep 22 '21 at 15:27

0 Answers0