From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA12271; Tue, 10 Jul 2001 00:09:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA12267 for ; Tue, 10 Jul 2001 00:09:10 +0200 (MET DST) Received: from str12.sobor.org (adsl-63-198-183-99.dsl.snfc21.pacbell.net [63.198.183.99]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f69M99b12556 for ; Tue, 10 Jul 2001 00:09:09 +0200 (MET DST) Received: from quasar.ipa.nw.ru (anza.sobor.org [192.168.123.51]) by str12.sobor.org (Postfix) with ESMTP id 522AEAC065 for ; Mon, 9 Jul 2001 14:56:56 -0700 (PDT) Message-ID: <3B4A2B48.8B013EA7@quasar.ipa.nw.ru> Date: Mon, 09 Jul 2001 15:08:08 -0700 From: "Alexander V. Voinov" Organization: Fear of the Lord is the beginning of wisdom X-Mailer: Mozilla 4.75 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: caml Subject: Re: [Caml-list] GC and interoperability with C Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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? Alexander ------------------- 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