Skip to content
Prev 6043 / 10988 Next

[Rcpp-devel] Delayed usage of auxiliary memory in RcppArmadillo

Some C++ 101 insights below.

Le 2013-06-10 23:07, Simon Zehnder a ?crit?:
SO WRONG.
here the default constructor or arma::mat is called. What it does is 
entirely up to the implementation of the class.
wrong again.

what happens here is in two steps.

  - first, an arma::mat is constructed, using the so called advanced 
constructor. this does use the auxiliary memory to create a temporary.
  - second, the assignment operator is used to copy the temporary into 
"maybeM"

So indeed maybeM does not use the auxiliary memory, I hope now you 
understand why.
Everything is possible, it is a decision made by the implementation. 
e.g. for Rcpp classes copy construction means just cheap pointer copies, 
not data copies.
armadillo is implemented with more traditional copy semantics.
wrong conclusion. what you demonstrated here is that you need to study 
basic c++ (assignment operators, copy construction, ...) :)

now, things would be different with move semantics in c++11. Not sure 
armadillo has implemented them already, but I'm pretty sure that is not 
what you were talking about.

Romain