From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA29185 for caml-redistribution; Sun, 14 Feb 1999 19:14:26 +0100 (MET) 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 CAA14744 for ; Sun, 14 Feb 1999 02:39:13 +0100 (MET) Received: from mail2.digital.com (mail2.digital.com [204.123.2.56]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id CAA03964 for ; Sun, 14 Feb 1999 02:39:10 +0100 (MET) From: doligez@pa.dec.com Received: from six.pa.dec.com (six.pa.dec.com [16.4.80.66]) by mail2.digital.com (8.9.1a/8.9.1/WV2.0d) with SMTP id RAA32546; Sat, 13 Feb 1999 17:39:04 -0800 (PST) Received: by six.pa.dec.com; id AA22476; Sat, 13 Feb 1999 17:39:03 -0800 Message-Id: <199902140139.AA22476@six.pa.dec.com> To: Andrew Martin Cc: caml-list@inria.fr Subject: Re: "C" Finalizers In-Reply-To: Message of Wed, 10 Feb 1999 09:27:39 -0600 from Andrew Martin <36C1A56B.3C6061B8@ibmoto.com> Date: Sat, 13 Feb 1999 17:39:03 -0800 X-Mts: smtp Sender: weis >From: Andrew Martin >Are there any restrictions on the things that a finalizer (the first >element of a block tagged with Final_tag) can do safely? Definitely yes. > For instance, >can it allocate memory from the Ocaml heap? No. > Can it use callback to apply a closure to a value? No because that could allocate memory. > Is there any interest in exploring the >posibility of introducing a general-purpose finalization mechanism into >the Ocaml language itself ? This is hard to do for two reasons. First, you have to specify what it means exactly, and what happens when the finalization function reconnects (parts of) the data structure that is about to be freed. Then you have to implement it without bugs. >Unfortunately, to track the improvement gained by re-ordering, you >really need to be able to know whether a node is referenced by the >outside world. While one could concoct various schemes involving arrays >of weak pointers to accomplish this, they all feel complicated and >contrived -- they very thing I was trying to avoid by writing in Ocaml >in the first place. Yet, this is what weak pointers are designed for. Maybe it would be easier with a library of well-chosen functions implemented on top of the weak pointer primitives ? > The most natural way do deal with the problem is to >define a finalizer that recursively decrements ref counts. That would be very inefficient, but if you really want to do it, you should be able to write such a finalizer in C without too much work. >Obviously, providing a general finalization mechanism in the Ocaml >language itself would be fraught with difficulty e.g. what's to prevent >the finalizer from creating new references to the object (and hence >indirectly to its descendants) that we just decided to free ? Still, >I thought I'd raise the issue and see if anyone is thinking about it. We do think about it from time to time, but the demand-to-difficulty ratio is really bad. -- Damien