[Rcpp-devel] Best way to return raw array

Darren Cook darren at dcook.org
Sat Sep 3 02:48:49 CEST 2011


>> > Maybe this would do
>> > 
>> >  double *p=third_party_function(nn);
>> >  NumericVector ret(nn);           // new memory
>> >  copy(ret.begin(), ret.end(), p); // untested
>> >  delete p;
>> >  return ret;
>> > 
>>> | where third_party_function() is C legacy code that is
>>> documented as | returning a block of memory of size nn that the
>>> client should take | ownership of.

> If third_party_function is really C legacy code, wouldn't the block
> of code be more likely to have been allocated with a 'malloc', and
> so you should release it with a 'free'?

Good point :-)
The legacy code API will tell me how it should be deleted. (With some
APIs it will be a special function.)

Darren

-- 
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)


More information about the Rcpp-devel mailing list