From ripley at stats.ox.ac.uk  Mon Jun 13 10:52:45 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon, 13 Jun 2005 09:52:45 +0100 (BST)
Subject: [Rd] memory allocation problem under linux
In-Reply-To: <1118652187.42ad471bd917f@posta.studio.unibo.it>
References: <1118652187.42ad471bd917f@posta.studio.unibo.it>
Message-ID: <Pine.LNX.4.61.0506130947360.23218@gannet.stats>

You keep on sending similar messages -- this is at least the third.  You 
need to find out where the segfault is occurring using gdb, and you have 
not told us.

Very likely this results from some previous memory corruption in your 
compiled code: try valgrind (see `Writing R Extensions') to try to track 
that down.

Since this fails with malloc, it is not really an R question.

On Mon, 13 Jun 2005, antonio.dinarzo at studio.unibo.it wrote:

> 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!).

The last is probably just good luck.

-- 
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



[Rd] memory allocation problem under linux
Prof Brian Ripley