[R] memory allocation problem under linux

antonio.dinarzo@studio.unibo.it antonio.dinarzo at studio.unibo.it
Sun Jun 12 14:17:27 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 this code:
  #define NMAX 256
  long **box;
  ...
  box   = (long **)R_alloc(NMAX,   sizeof(long *));

gives a null pointer, so subsequent line:
  for (i=0; i<NMAX; i++) box[i] = (long *) R_alloc(NMAX, sizeof(long));
gives a SIGSEGV signal.
In the same shared library, I have a 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.

Any idea on where the problem can reside? (Note that this not happens under WinXp).
And just another question. When R_alloc fails, should-it terminate the function
with an error, without returning control to the function?




More information about the R-help mailing list