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
[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: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] GC and interoperability with C
> 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.
    void register_global_root (value *);
    void remove_global_root (value *);
in memory.h.
After that, you must be careful of always accessing values through the
pointer, not directly.

Jacques Garrigue
Bug reports:  FAQ:
To unsubscribe, mail  Archives: