Message-ID: <92FD2DE5-0622-464B-BFF5-AA66881CD0E5@r-project.org>
Date: 2005-04-15T01:30:09Z
From: Simon Urbanek
Subject: dynamic array output by .C
In-Reply-To: <58618a62050414150165aae64@mail.gmail.com>
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