[R] When exactly do I need R_alloc when using the .Call() interface?

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Dec 21 19:45:05 CET 2011

First, the posting guide asked for questions about compiled code to be 
asked on R-devel.  So I will be brief.

You use R_alloc or Calloc in place of malloc/calloc.  Use R_alloc where 
code might be interrupted.

There are many examples in R's own packages and the recommended packages.

On 21/12/2011 16:34, michael.zombok at googlemail.com wrote:
> Hi,
> I am trying to implement an algorithm in C which will be called via the
> .Call() interface.
> While reading the 'Writing R Extension' manual, I stumbled upon the
> R_alloc() function for allocating storage for C objects. The manual says
> it should be used to allocate storage if an C object is needed/created
> while manipulating R objects within a function called via the .Call()
> interface.
> Because none of the examples in the manual uses R_alloc(), I wonder when
> it is needed? If I create an pointer in C or a single variable it seems
> not necessary?! (Or at least it is never called in the examples.). Is it
> necessary when creating an array? Or better when exactly should I use
> R_alloc?
> Thanks!
> Best regards,
> Michael
> ______________________________________________
> R-help at 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.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list