[Rcpp-devel] Rcpp vector classes vs std::vector for custom class member variables

Jon Clayden jon.clayden at gmail.com
Tue Oct 8 13:04:24 CEST 2013


Dear all,

I'm new to Rcpp and this mailing list. I did look for a previous answer to
this question, but it's hard to summarise succinctly so I may have missed
something. Apologies if so.

I'm defining a custom class, an object of which will need to survive across
various calls back and forth between R and C++, so I plan to use the XPtr
class to wrap a pointer. My question is, what are the advantages and
disadvantages of using Rcpp vector classes (vs std::vector) for member
variables? To be more concrete, I mean

class Foo
{
private:
  Rcpp::NumericVector bar;
}

vs

class Foo
{
private;
  std::vector<double> bar;
}

Are there garbage collection issues when these live inside an XPtr<Foo>?
Are there speed advantages of std::vector<double> over Rcpp::NumericVector
for general use? Any input would be welcome. Thanks in advance.

Great work on Rcpp, by the way. I've been hearing very good things for
quite some time, but wasn't sure if it was worth dusting off my slightly
rusty C++ for. Suffice to say I think it was. The API is very clean and
returning to the standard R API will be painful...!

All the best,
Jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20131008/ee06533b/attachment.html>


More information about the Rcpp-devel mailing list