Another solution is the one used for a long time in the rpart code.
The R code called "rpart1", which does the work, keeps a static pointer to the 
object, 
does NOT
release it's memory, and returned the size of the object.

Then the R code allocates appropriate vectors and called "rpart2", which filled 
in the 
result and
released the dynamic memory.

This was written before .Call was available.  It works, but I agree with Bill 
Dunlap that 
you should use
.Call.

Terry T.


On 06/20/2013 05:00 AM, r-devel-requ...@r-project.org wrote:

Hi there,

Although I'm a quite experienced R user and know my ways in C, I stumbled
upon a problem I don't know how to solve. Therefore, I hope someone can
provide me with the information or pointers I need in order to understand
the way in which the communication between R and C occurs. I have the
following C code which basicallly reflects what I want:

typedef struct
{
        float *array;
        size_t used;
        size_t size;
} Array;

void main2R()
{
       Array a;
       examplefunction(&a);   /*fills and dynamically grows a->array*/
}

Now I would want to return a.array or a->array to R. According to the R
manuals, the compiled C code should not return anything except through its
arguments. The problem here is, I have a dynamically growing array, and I
have no idea what to pass on to C from R in order to let that work.
The word 'should' indicates that the compiled code may return something in
special circumstances, but I have no idea how to get a.array in R.

So my question is simply this: How on earth do I get the information in the
float array 'a.array' in R? Is it even possible or should I rewrite my C
code using Call in R?

Another, not preferred, options is to pre-allocate the array/vector in R on
a fixed (large-enough) size? Or do I miss something here?

Regards.

Tee-Jay-Ardie



        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to