[Rd] dynamic array output by .C

Simon Urbanek simon.urbanek at r-project.org
Fri Apr 15 01:29:25 CEST 2005


On Apr 14, 2005, at 6:01 PM, Tib wrote:

> from the examples of Writing R Extensions,  I see one still has to
> declare the size of arrays by NEW_NUMERIC(n) or
> allocVector(REALSXP,n), how can I extend arrays?

AFAIR you cannot extend vectors - it's like in C, you cannot extend  
allocated memory without changing the pointer (i.g.). In order to get  
a vector of a different size, you have to allocate a new one and copy  
the common contents. If you are concerned about efficiency, why don't  
you just use arbitrary large vectors and pass along the number of  
used elements? Then you can easily add elements without re-allocating  
and just return the number of elements used after the operation. That  
way you can control the probability of having to allocate a new  
vector, possibly making it zero.

Cheers,
Simon



More information about the R-devel mailing list