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

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Mar 11 22:17:18 AEDT 2003


On 11-Mar-2003, Ondrej Bojar <oboj7042 at ss1000.ms.mff.cuni.cz> wrote:
> On Tue, 11 Mar 2003, Fergus Henderson wrote:
> > 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)).
> 
> Does this mean, that if I do not keep a pointer to the data on C global
> variables, C stack or Mercury stack then the garbage collector might
> (will) release the data from the memory. And then, when I look up the
> "extra" pointer stored on the C heap and dereference it, I touch the
> released memory block. Did I get it correctly?

Yes.

If this is a problem, one solution is to allocate your memory using
GC_malloc() rather than malloc().

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