Version française
Home     About     Download     Resources     Contact us    
Browse thread
collecting the collector?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: collecting the collector?
> I have some code written in OCaml that I've exported to .a file (using the
> standard procedure outlined in the OCaml manual, including using
> -output-obj); this .a file will obviously include the OCaml runtime system,
> and thus its precise collector.  I'm linking this .a file with a C program
> that has its own garbage collector, the Hans-Demers-Weiser conservative
> collector.

I don't know of any OCaml user that actually tried this, but I see no
reason why it shouldn't work.  The OCaml heap is composed of a number
of relatively large blocks (typically 256K), all allocated with malloc()
and chained together for easy reference.  Other data structures for
the OCaml runtime are either in malloc()-ed blocks or in global variables.

A conservative collector a la Boehm-Weiser will just see a bunch of
malloc()-ed blocks, with many pointers from one inside another, and
sufficient chaining to ensure that they are always live as long as the
OCaml code is active.  I can't see anything that could go wrong.

> I'm wondering if anyone has any stories from doing something of this sort
> before, or could at least speculate on how the two collectors will interact.
> I'm presuming that the OCaml collector will be "contained" within the area
> governed by the conservative collector, and so that potential mishaps will
> arise from the Caml collector doing something pointer unsafe,

I'm not sure what you mean by "pointer unsafe" here.  If you're
thinking about those hacks that break conservative collectors, such as
storing the difference or the XOR between two pointers, OCaml doesn't
do any of these.

- Xavier Leroy