[Rd] memory allocation problem under linux

antonio.dinarzo@studio.unibo.it antonio.dinarzo at studio.unibo.it
Mon Jun 13 10:43:07 CEST 2005


I have some compiled code that works under winXp but not under linux (kernel
2.6.10-5). I'm also using R 2.1.0
After debugging, I've discovered that in this code:
  #define NMAX 256
  long **box;
  ...
  box   = (long **)R_alloc(NMAX,   sizeof(long *));   //<---HERE THE SIGSEGV
  for (i=0; i<NMAX; i++) box[i] = (long *) R_alloc(NMAX, sizeof(long));
inside the *first* call to the function R_alloc I have a segmentation fault.
Changing R_alloc with Calloc and malloc gives the same result.
However, in the same shared library, I have another function with this code:
  partitions=16;
  ...
  h2=(long **)R_alloc(partitions,sizeof(long *));
  for (i=0;i<partitions;i++)
      h2[i]=(long *)R_alloc(partitions,sizeof(long));
that works! Naturally, I've tried to change NMAX from 256 to 16, without any
success.
I've changed optimization flags from O2 to O and O2, without success.
Any idea on where the problem *should* reside? (Note that this not happens under
WinXp!).

Antonio, Fabio Di Narzo.



More information about the R-devel mailing list