[R-SIG-Mac] Memory length in C

Simon Urbanek Simon.Urbanek at math.uni-augsburg.de
Mon Oct 4 17:18:33 CEST 2004


On Oct 4, 2004, at 4:22 PM, Maartje Raijmakers wrote:

> I suspect memory problems. Therefore I want to do the following, but I 
> don't
> know how:

BTW: you may want to CC this to R-help (in case you didn't), because 
this is not a Mac-specific problem.

> I use C - routines which I call from R with .C (and C routines that are
> called from fortran by lsoda in the odesolve package)
> One of these C routines has as an argument a pointer to an array of 
> doubles.
>
> Now, I want to check the length of this array within the C-routine.
> Does anyone know how I should do that?

AFAIK the .C function has no way of providing the array length - this 
is one of the reasons why .Call is recommended. You can, however, 
supply the length yourself in an extra parameter, such as for example:

a<-rnorm(100)
.C("myfunc", as.double(a), as.integer(length(a)))

and in C:

void myfunc(double *a, int *len);

I'm not quite sure, but there may be some low-level debugging tools in 
R, such as using your own memory allocation routines, but I'm not sure 
if that will help in your case. For Mac-specific debugging there is a 
lot of very powerful tools for memory management inspection, see man 
malloc for details.

Cheers,
Simon

---
Simon Urbanek
Department of computer oriented statistics and data analysis
University of Augsburg
Universitätsstr. 14
86135 Augsburg
Germany

Tel: +49-821-598-2236
Fax: +49-821-598-2200

Simon.Urbanek at Math.Uni-Augsburg.de
http://simon.urbanek.info



More information about the R-SIG-Mac mailing list