From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 01813BB81 for ; Fri, 17 Dec 2004 23:56:03 +0100 (CET) Received: from annexia.force9.co.uk (annexia.force9.co.uk [212.56.101.183]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iBHMu2rv022388 for ; Fri, 17 Dec 2004 23:56:02 +0100 Received: from rich by annexia.force9.co.uk with local (Exim 3.36 #1 (Debian)) id 1CfR10-0002Po-00; Fri, 17 Dec 2004 22:56:02 +0000 Date: Fri, 17 Dec 2004 22:56:02 +0000 To: Jonathan Roewen Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] GC, Anonymous Functions, and C Message-ID: <20041217225602.GA8550@annexia.org> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="MGYHOYXEY6WxJCY8" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6+20040722i From: Richard Jones X-Miltered: at nez-perce with ID 41C36402.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 ocaml:01 ocaml:01 functions:01 functions:01 passing:01 caml:02 caml:02 somewhere:02 ought:03 root:03 root:03 dec:03 context:04 X-Attachments: type="application/pgp-signature" name="signature.asc" X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: --MGYHOYXEY6WxJCY8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Dec 18, 2004 at 10:55:23AM +1300, Jonathan Roewen wrote: > Hi, >=20 > When passing an anonymous ocaml function to a C function, is it safe > to store that value in an array, and then call it later at an abitrary > time, or will the GC reclaim it? And if so, what should be done to > stop the GC from doing so? >=20 > Basically, we're trying to do interrupt handling from OCaml, and need > to store the anonymous functions somewhere for the IDT to jump into, > to provide a little context for the problem. The GC might reclaim the value (function, or whatever) unless you register it as a global root. To do this you need to call caml_register_global_root on each value which you put in the array. Furthermore you ought to call caml_remove_global_root when you remove the value from the array and no longer need it. Rich. --=20 Richard Jones. http://www.annexia.org/ http://www.j-london.com/ >>> http://www.team-notepad.com/ - collaboration tools for teams <<< Merjis Ltd. http://www.merjis.com/ - improving website return on investment http://youunlimited.co.uk/ - Personal improvement courses --MGYHOYXEY6WxJCY8 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFBw2QC4le1M6q9pzoRAhrCAKDiDWnziUC+B4cCFkjbKNxE/VPDJwCgjNMj vnbQXsNbzIliElMiah//Zb4= =xAYt -----END PGP SIGNATURE----- --MGYHOYXEY6WxJCY8--