[Rd] malloc/calloc/strdup and R's aequivalents

From: oliver <oliver_at_first.in-berlin.de>
Date: Sun, 18 Mar 2012 03:30:52 +0100


Hello,

when looking at "Writing R Extensions"
with mem-allocation in mind, I wondered, which functions to use to substitute
malloc(), calloc(), realloc() and strdup() and free().

It looked like Calloc() or R_Calloc() might be useful for some of my tasks, but when trying to use R_Calloc() for example, I got some error messages which I don't see where they are coming from.

Maybe I just have forgotten to includ ethe right header file?

So, how to use Calloc() / R_Calloc()?
What is the prototype of this function/macro?

And: what if I just want to easily substitute strdup()/free()?

mkChar seems not to be the right thing, because, what I found in the above mentioned documentation, says,m that a C-string is fed in, but CHARSXP is what I get as result.

What I try to do, is, to pick some code and port it to R. If I need to rewrite a lot of stuff, just because I need to adapt to R, this would be more effort than if it would be possible just to have some functions, that could make porting easier.

For example, if I want to resuse a function, that opens a file and needs a char* stringname
then it would add more effort if I need to go via CHARSXP or so.

I would need to rewrite many pieces of the code.

(Should I implement my own kind of R_str_alloc() ?)

My main problem at the moemnt is, that I can use R_alloc() but when I try to use Calloc() or R_Calloc() I can't compile.

So, what header-files are necessary, and what are the prototypes of these functions?

If nothing of that stuff works, I would need to use the original calloc() / free() functions, which are deprecated in the above mentioned manual.

Ciao,

   Oliver

P.S.: Also I wonder... R-alloc() does not need a free()-like call?

      Is it freed automaticlaly?
      And at which time?
      In the docs is mentioned, at the end of the .C/.Call/.External call.
      Does this mean, this is freed/reclaimed automatically, when returning
      from the C-world to the R-world?
      At (after) return of the extension's code?

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun 18 Mar 2012 - 02:32:33 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 18 Mar 2012 - 05:20:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive