[Rcpp-devel] Yet another design question regarding Rcpp
Douglas Bates
bates at stat.wisc.edu
Tue May 4 22:26:48 CEST 2010
In the files src/MatrixNs.{h,cpp} of the lme4a package (the
development version of lme4, available only from R-forge) I create C++
classes that parallel some of the S4 classes in the Matrix package for
R. Most of the time I apply operations in those classes to numeric
vectors passed as arguments or components of arguments from R. Thus
many of the function signatures include arguments of the form
NumericVector const&
If I have a more complex operation to perform in C++ using temporary
storage I could allocate the storage by declaring
NumericVector bar(foo.size());
or something like that, even though this vector will never be touched
by R. I think this is the simplest approach so that I only need to
use one set of function signatures in the MatrixNs.h declarations.
Alternatively I could declared multiple function signatures for both
NumericVector const& and std::vector<double> const& arguments and
allocate the temporary storage using std::vector<double> instead of
NumericVector.
Or I could even declare all the function arguments as
std::vector<double> const& and convert the NumericVector objects to
that form (although I think that might involve some copying) before
passing them.
I am currently favoring using NumericVector to allocate the
temporaries, even though the storage must be allocated and freed
through R's mechanisms.
Opinions?
More information about the Rcpp-devel
mailing list