English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2001-07-09 (06:59)
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: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr