From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id CFF5DBB91 for ; Sat, 18 Dec 2004 00:05:34 +0100 (CET) Received: from mail.davidb.org (adsl-64-172-240-129.dsl.sndg02.pacbell.net [64.172.240.129]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iBHN5WsJ002297 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 18 Dec 2004 00:05:34 +0100 Received: from davidb by mail.davidb.org with local (Exim 4.42 #1 (Debian)) id 1CfRAB-0005L9-GW; Fri, 17 Dec 2004 15:05:31 -0800 Date: Fri, 17 Dec 2004 15:05:31 -0800 From: David Brown To: Jonathan Roewen Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] GC, Anonymous Functions, and C Message-ID: <20041217230531.GA20427@old.davidb.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6i X-Miltered: at concorde with ID 41C3663C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 caml-list:01 wrote:01 ocaml:01 interfacing:01 val:01 ...:98 ...:98 functions:01 passing:01 int:01 argument:01 caml:02 callback:02 objective:02 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.0 X-Spam-Level: On Sat, Dec 18, 2004 at 10:55:23AM +1300, Jonathan Roewen wrote: > 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? You'll need to register the value as a global root, using register_global_root. Please see the Interfacing C with Objective Caml, where there is brief mention of this function. It is also important to dereference the value each time you use it. static value hook = Val_int (0); ... hook = passed_argument; register_global_root (&hook); ... callback (hook, arg); You can also use remove_global_root() later to remove the reference. Dave