[Rcpp-devel] Range constructor and memory allocation

Dirk Eddelbuettel edd at debian.org
Wed Feb 19 00:42:01 CET 2014

On 18 February 2014 at 19:12, Gregor Kastner wrote:
| Dear all,
| while writing an iterator hack for the problem encountered a few hours ago
| and posted here:
| https://www.mail-archive.com/rcpp-devel@lists.r-forge.r-project.org/msg06810.html,
| I have noticed that the default behavior for the range constructor for e.g.
| Rcpp::NumericVector seems to be to allocate fresh memory:
| arma::mat obj1(5, 10, arma::fill::zeros);
| Rcpp::NumericVector obj2(obj1.begin(), obj1.begin() + 5);
| obj2 = 1.;
| Rprintf("obj1: %f, obj2: %f\n", obj1(0,0), obj2(0));
| yields that obj1 and obj2 differ.
| Is there any way to tell the range constructor to reuse existing memory
| similarly to the (Rcpp)Armadillo feature copy_aux_mem = false or am I
| missing something more subtle?

To use an advanced constructor for Armadillo object requires Armadillo to
provide such a constructor in the first place. See 


and I can only spot them for outright matrix, rowvec, colvec objects, but not
for ranges.

For Rcpp constructor, things are different too as Kevin kindly pointed out


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

More information about the Rcpp-devel mailing list