[Rcpp-devel] Trouble passing arguments to R functions that have been passed in (maybe)

Christian Gunning xian at unm.edu
Wed Sep 12 07:56:08 CEST 2012


On Tue, Sep 11, 2012 at 3:00 AM,
<rcpp-devel-request at lists.r-forge.r-project.org> wrote:
>
> It seems to be the casethat when the memory issue occurs, garbage
> collection has just been called by R, at least according to gcinfo.In
> particular, it is called when bar is called and cleans up the arguments
> that bar is about to use, thus causing a problem.
>
> Is there a way to ensure the safety of the arguments that are sent back
> to R?

I've gotten in the habit of being very explicit with Rcpp -- limiting
the use of nested functions, doing one step per line.  I'm don't
understand the internals enough to understand the exact
metaprogramming/template details, and I've often seen "odd behavior"
disappear when I unpack a long, complicated line into component lines
of code. This is similar to Dirk's comment about limiting use of
temps.

Also, have you looked at Armadillo for submatrix access?  You can
easily pull out columns/rows into NumericVectors.  Sometimes I find
the logical separation between pure C++ (arma) and chameleon SEXP/Rcpp
conceptually helpful.

Curious to hear your results,
Christian
University of New Mexico

-- 
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!


More information about the Rcpp-devel mailing list