[Rcpp-devel] returning array from C

Steve Jaffe sjaffe at riskspan.com
Tue Jun 11 17:51:26 CEST 2013

Is there a way to 'wrap', say, an array of double allocated on the heap in C/C++ and return it to R without copying, ie as the data inside a REALSXP?

(Let's say for example that this array allocation is in a 3rd-party library which can't be modified)

Looking at the 'wrap' code it appears that copying is done in all cases (except for the 'external pointer').

Clearly the memory ownership issue is one that would need to be handled. Handing over ownership to R would seem the simplest approach. But it would be more interesting to be able to integrate with something like boost::shared_array so that the lifetime would be correctly managed across both the C and R environments.

I've read through Rcpp documentation and "Writing R Extensions" without coming up with a good answer, but I'm new to this and I suspect someone familiar with R internals (unlike me) would immediately see what was involved.

Thanks for your help.


More information about the Rcpp-devel mailing list