[Rcpp-devel] function created from cxxfunction modifies input?

Dirk Eddelbuettel edd at debian.org
Sun Jul 8 02:23:03 CEST 2012

On 8 July 2012 at 01:46, Alexandre Bujard wrote:
| Hi Joshua,
| When you declare "NumericVector xx(x)" xx is a copy of the pointer x. But they
| both address the same location in the memory.


| What you need here is to do a "deep copy" of the vector x. The best was to do
| that in Rcpp is to use the function "clone".


Are created a few object, eg via

   NumericVector xx(x.size());   // ctor using int n of size

| Also declaring your vector xx with "const" will guarantee that your vector x
| will not be modified by the function.

That is not true, I think. C++ will make sure xx remains const, but we care
about is the memory pointed to, and that doesn't get the const protection.

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

More information about the Rcpp-devel mailing list