From: doligez@pa.dec.com
To: Andrew Martin <amartin@ibmoto.com>
Cc: caml-list@inria.fr
Subject: Re: "C" Finalizers
Date: Sat, 13 Feb 1999 17:39:03 -0800 [thread overview]
Message-ID: <199902140139.AA22476@six.pa.dec.com> (raw)
In-Reply-To: Message of Wed, 10 Feb 1999 09:27:39 -0600 from Andrew Martin <amartin@ibmoto.com> <36C1A56B.3C6061B8@ibmoto.com>
>From: Andrew Martin <amartin@ibmoto.com>
>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
prev parent reply other threads:[~1999-02-14 18:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-02-10 15:27 Andrew Martin
1999-02-14 1:39 ` doligez [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199902140139.AA22476@six.pa.dec.com \
--to=doligez@pa.dec.com \
--cc=amartin@ibmoto.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox