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 VAA32131; Thu, 1 Apr 2004 21:21:36 +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 VAA32062 for ; Thu, 1 Apr 2004 21:21:35 +0200 (MET DST) Received: from xanadu.ece.ucsb.edu (xanadu.ece.ucsb.edu [128.111.56.51]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i31JMJjq009377; Thu, 1 Apr 2004 21:22:20 +0200 Received: from [128.111.56.252] (gimli.ece.ucsb.edu [128.111.56.252]) by xanadu.ece.ucsb.edu (8.12.10/8.12.10) with ESMTP id i31JLWeO028812; Thu, 1 Apr 2004 11:21:32 -0800 (PST) In-Reply-To: <1E3A29A6-83FF-11D8-BD34-00039310CAE8@inria.fr> References: <1E3A29A6-83FF-11D8-BD34-00039310CAE8@inria.fr> Mime-Version: 1.0 (Apple Message framework v613) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit Cc: Damien Doligez From: Shivkumar Chandrasekaran Subject: Re: [Caml-list] Weak pointers and Gc.finalise Date: Thu, 1 Apr 2004 11:21:27 -0800 To: caml-list@inria.fr X-Mailer: Apple Mail (2.613) X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; shivkumar:01 shiv:01 caml-list:01 pointers:01 damien:01 marshaling:01 3.07:01 val:01 val:01 elt:01 abstr:01 endline:01 marshaled:01 --shiv--:01 bin:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Keywords: X-UID: 20 On Apr 1, 2004, at 9:07 AM, Damien Doligez wrote: > >> (Side note: I am trying to avoid Marshaling the Bigarray unless it is >> going to be garbage-collected. But if I cannot detect that, then I >> have to always Marshal it whenever its entries change, which is very >> inefficient.) > > I'm not sure I understand. The finalisation function is called when > the value is about to be garbage-collected. Why can't you just > marshal it at that point? > This session might explain what I am trying to do, and why I could not do it. -----------start session on Mac OS X 10.3.3--------------- Objective Caml version 3.07+2 # #load "bigarray.cma";; # open Bigarray;; # let fname = "Trashme.dat";; val fname : string = "Trashme.dat" # let final bat = let fd = open_out_bin fname in Marshal.to_channel fd bat []; close_out fd;; val final : 'a -> unit = # let wt = let wtt = Weak.create 1 in let ba = Array1.create float64 c_layout 1000 in Gc.finalise final ba; Weak.set wtt 0 (Some ba); wtt;; val wt : (float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Array1.t Weak.t = # Weak.check wt 0;; - : bool = true # Gc.compact ();; - : unit = () # Weak.check wt 0;; - : bool = false # Sys.file_exists fname;; - : bool = false # ---------that's it----------------------- As you can see my finalisation function on the bigarray tries to marshal the data to a file. However, after Gc.compact the bigarray is no longer reachable from anywhere in my code, but still, the finalisation routine has not been called, as is evident from the Sys.file_exists call. (I have also tried putting print_endline "Ha" statements inside the finalisation routine to check this.) I do see that Gc.full_major calls the finalisation calls. One way out for me is to check if the data has been marshaled successfully, otherwise I just issue a Gc.full_major call myself. However, I don't want to exercise the GC unnecessarily. Any advice? Thanks, --shiv-- ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners