[Rcpp-devel] Range constructor and memory allocation

Kevin Ushey kevinushey at gmail.com
Tue Feb 18 19:56:40 CET 2014


Hi Gregor,

I don't think it's possible at this point. Some technical details follow:

All R data internally is a SEXPREC, ie, a C struct full of different
bits of information. The data part of a SEXPREC is forced to a
specific offset from the C structure, e.g. from Rinternals.h:

/* Under the generational allocator the data for vector nodes comes
   immediately after the node structure, so the data address is a
   known offset from the node SEXP. */
#define DATAPTR(x) (((SEXPREC_ALIGN *) (x)) + 1)

Since Rcpp objects are just proxy wrappers over R objects, for Rcpp to
be able to reuse memory, we would have to construct the SEXPREC in the
correct memory location so that the resulting DATAPTR call happens to
fall where the data is. However, I'm not sure how we could reserve
that space for the SEXPREC.

Other data structures that just contain a pointer to their data,
rather than requiring that they lie a specified offset away, don't
have this problem (I imagine this is why e.g. Armadillo can reuse
memory)

Maybe others have more thoughts.

Cheers,
Kevin


More information about the Rcpp-devel mailing list