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 HAA26020; Thu, 12 Jul 2001 07:48:52 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id HAA26022 for ; Thu, 12 Jul 2001 07:48:51 +0200 (MET DST) Received: from str12.sobor.org (adsl-63-198-183-99.dsl.snfc21.pacbell.net [63.198.183.99]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f6C5mob06284 for ; Thu, 12 Jul 2001 07:48:50 +0200 (MET DST) Received: from quasar.ipa.nw.ru (anza.sobor.org [192.168.123.51]) by str12.sobor.org (Postfix) with ESMTP id 4301EAC05E for ; Wed, 11 Jul 2001 22:36:06 -0700 (PDT) Message-ID: <3B4D3A02.77361186@quasar.ipa.nw.ru> Date: Wed, 11 Jul 2001 22:47:46 -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 References: <3B493A40.1B2985FE@quasar.ipa.nw.ru> <20010709155900C.garrigue@kurims.kyoto-u.ac.jp> <3B49C748.9CFB4E6@quasar.ipa.nw.ru> <20010710094419W.garrigue@kurims.kyoto-u.ac.jp> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi All, Jacques Garrigue wrote: > Either these values are long ints, and you can just copy them, or they > are pointers, and you just do as I explained. > > value my_func(value a, value b) > { > value *loca = (value*)malloc(sizeof(value)); > value *locb = (value*)malloc(sizeof(value)); > *loca = a; *locb = b; > register_global_root(loca); > register_global_root(locb); > > .... > } > > Now you can put loca and locb directly in you C data structure, the > real data being accessed by *loca, *locb. > > Of course, don't forget that you must unregister your global roots > before freeing loca and locb. I've played a bit with this, and I have an observation that huge amount of time is spent on remove_global_root(a). I will describe the problem, to let you better understand to context. I have an implementation of B+-tree, with threading, allowing duplicates and logarithmic access to the item number. Of course it would be fun to reimplement it in OCaml, but I have enough fun besides this, and enough serious tasks for which specifically I started to consider OCaml; also, I'd like to see on this example how much could I get in the interaction between C and OCaml; next, the module is tested and used for years, and I see no point to duplicate the work. If successful, I'd like to make it available for OCaml community. I store arbitrary OCaml objects in the nodes of the tree, using the advice quoted above. And I see that the performance of an application is very different with and without remove_global_root(a). Am I doing something wrong (besides the very idea of building a complex C structure, containing lots of OCaml objects; let's assume that the idea is justified in this or that case)? Thank you in advance 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