On Jul 20, 2009, at 7:06 PM, Dan Kelley wrote:


I am trying to write a C function to create a vector of integers that can be used by the R calling function. I do not know the size of the vector in the R calling function. (Well, actually, I have an upper limit on the size, but that is so large that R cannot allocate it. What I'm doing in the function is to do a sieving procedure, and the result will be small enough to fit
into my machine's memory.)

My reading of sections 6.1.1 and 6.1.2 of the guide on writing R extensions has left me a bit confused. Under R_alloc, I read "R will reclaim the memory at the end of the call" which seems to suggest the storage won't be made available afterwards, so that's not what I should use. As for the alterntaive, under Calloc, I read "This memory lasts until freed by the
user", and it's clear that this is to be done within the C function in
question.

Summary question: how can I allocate memory withing a C function, making it
available to an R function that calls the C function?

Thanks.  Dan.
--


You might look at the package bigmemory to see how they attacked the problem. In fact if my reading of their documentation is correct they may have already done your work for you:

http://www.stat.yale.edu/~jay/bigmemory

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to