[mercury-users] Heap space limited for C when called from Mercury?

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Mar 11 05:36:23 AEDT 2003


On 10-Mar-2003, Ondrej Bojar <oboj7042 at ss1000.ms.mff.cuni.cz> wrote:
> I'm calling a lot of C/C++ code from Mercury and this C++ code allocates
> some (not too much, in current relations) memory. However, the C++ code
> crashes on a 'new' something.
> 
> Is the size of heap limited for C code? Or is the heap probably already
> corrupt at that state?

No, the size of the C heap is not really limited (except by the available
virtual memory and ulimit settings).  Yes, the symptoms that you describe
indicate that the heap is already corrupt at that point.  There are a
number of debugging tools available to debug these kinds of problems.

One thing to be careful about is putting (pointers to) Mercury data
structures on the C heap.  The Boehm (et al) conservative garbage
collector, which is used by the Mercury implementation, will not scan
areas allocated with malloc() or with the standard "new".  So you must
make sure that any Mercury data structures pointed to from the C heap
are also pointed to from somewhere else (e.g. C global variables, the
C stack, or the Mercury stack(s)).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list