caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien Doligez <Damien.Doligez@inria.fr>
To: caml-list@pauillac.inria.fr
Subject: Re: Weak pointers
Date: Mon, 17 Mar 1997 20:19:00 +0100	[thread overview]
Message-ID: <199703171919.UAA04633@tobago.inria.fr> (raw)

>From: Frank Christoph <christo@nextsolution.co.jp>
>  Does this mean that even a full weak pointer can be erased?

Yes.  An empty pointer doesn't contain anything, so talking about
erasure is only meaningful for full pointers.

> What does "at any time" mean --- even if the pointer is still
>accessible from the root set, its contents can be erased?

Yes, but if that object is still reachable through some normal
(non-weak) pointer (i.e. any object except a weak array), then the GC
will not erase that weak pointer.  In other words, the GC will only
erase a weak pointer if this erasure makes the object unreachable,
thus deallocatable.

>  Is this intended to contrast with a usual reference, which must
>always be initialized?

I think initialisation is irrelevant.

>  Are weak pointers intended to model C pointers?

No.  Weak pointers are essentially a GC feature: pointers that are not
considered as making the pointed object reachable.

>  Could someone post an example of their use?

You can use them to implement hash-consing.  Assume you have some tree
data structure.  If you want to share the nodes wherever possible, you
can put every created node into a hash table.  Then when you are about
to create a new node, you first look in the hash table to see if the
same node has already been created.  If this is the case, you return
the old one from the hash table instead of creating a new one.

But the above prevents the GC from collecting the nodes when they
become unused, because they will always be reachable from the hash
table.  If you use weak pointers in your hash table, the GC will be
able to deallocate the dead nodes, but you still can have access to
the live ones through the weak pointers.

I don't have the weak hash table code yet, but it will certainly
be in the library at some point in the future.

Hope this helps.  If it's not clear, please ask more questions.

-- Damien





             reply	other threads:[~1997-03-18  9:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-03-17 19:19 Damien Doligez [this message]
1997-03-18 10:09 ` Kohler Markus
1997-03-18 15:54   ` Wolfgang Lux
1997-03-18 16:37     ` Kohler Markus
1997-03-18 17:32       ` Wolfgang Lux
  -- strict thread matches above, loose matches on Subject: below --
1997-03-30 17:13 Daniel de Rauglaudre
1997-04-01 10:57 ` Pierre Weis
1997-04-01 12:03   ` Daniel de Rauglaudre
1997-03-21 17:26 Damien Doligez
1997-03-20 12:12 Emmanuel Engel
1997-03-20 16:09 ` Kohler Markus
     [not found] <199703181607.RAA13208@tobago.inria.fr>
1997-03-18 17:08 ` Kohler Markus
     [not found] <199703181434.PAA12806@tobago.inria.fr>
1997-03-18 15:51 ` Kohler Markus
1997-03-18  7:43 Kohler Markus
1997-03-11 13:28 Objective Caml 1.04 released Xavier Leroy
1997-03-14  8:40 ` Frank Christoph
1997-03-17  9:13   ` Weak pointers Frank Christoph

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=199703171919.UAA04633@tobago.inria.fr \
    --to=damien.doligez@inria.fr \
    --cc=caml-list@pauillac.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;
as well as URLs for NNTP newsgroup(s).