Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] GC and interoperability with C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-07-09 (22:09)
From: Alexander V. Voinov <avv@q...>
Subject: Re: [Caml-list] GC and interoperability with C
Hi Jacques,

Jacques Garrigue wrote:
> > From what I see in the documentation, I see no way to 'lock' an OCaml
> > value on the heap so that it can be safely accessed from C code, and
> > then 'unlock' it, say, in the finalization function of some
> > Custom_block. In contrast to Python, e.g., where you just increment and
> > decrement the reference count.
> Yes, Python uses (used?) reference counting. More clever (and faster)
> GC's, like that of caml, have to move things around.
> > If this is right, the interaction of OCaml to C becomes one-way, you
> > cannot safely access OCaml world from arbitrary C code.
> Yes, you can. You just have to register a pointer with the GC, and
> everytime the target is moved around, the pointer will be updated.
> See
>     void register_global_root (value *);
>     void remove_global_root (value *);

Thank you. But how can get a pointer to a value, which came as a
parameter, say:

value my_func(value a, value b)
   make a sophisticated C structure, referring to these values...
   return result;

because &a and &b point to the stack which will vanish upon exit. Or do
the CAMLparam wrappers do what is needed in this case?

Bug reports:  FAQ:
To unsubscribe, mail  Archives: