antonio.dinarzo@studio.unibo.it
2005-Jun-12 12:17 UTC
[R] memory allocation problem under linux
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?
antonio.dinarzo@studio.unibo.it
2005-Jun-12 16:46 UTC
[R] memory allocation problem under linux
I've written:> #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.Sorry, that's not exact: I have a segmentation fault just *inside* R_alloc! Substituting R_alloc with malloc and Calloc gives the same error.