From simon.urbanek at r-project.org  Fri Apr 15 01:29:25 2005
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Fri Apr 15 01:30:09 2005
Subject: [Rd] dynamic array output by .C
In-Reply-To: <58618a62050414150165aae64@mail.gmail.com>
References: <58618a6205041414062f07d2a8@mail.gmail.com>
	<Pine.LNX.4.61.0504142212070.14473@gannet.stats>
	<58618a62050414150165aae64@mail.gmail.com>
Message-ID: <92FD2DE5-0622-464B-BFF5-AA66881CD0E5@r-project.org>

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


[Rd] dynamic array output by .C
Simon Urbanek