caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Warren Harris <warren@metaweb.com>
Cc: caml-list caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] understanding weak
Date: Fri, 31 Oct 2008 03:14:49 +0100	[thread overview]
Message-ID: <490A6A19.9050704@ens-lyon.org> (raw)
In-Reply-To: <D89537A8-F30A-4E39-ACFF-F81D2223B574@metaweb.com>

Warren Harris wrote:
> I'd like to understand better how ocaml's weak pointers operate. First,
> although it doesn't seem to be specified in the documentation, I assume
> that weak pointers will *not* be reclaimed (e.g. from a weak hash table)
> if the program retains some other reference to the object. I.e. the weak
> pointer must be the last remaining pointer to the object for reclamation
> to occur.

Yes, otherwise the program would crash.

> My second question relates specifically to my application. I would like
> to have a primary cache of objects, and a secondary index into
> sub-objects referenced from the primary cache. I.e. CacheA references
> objects of type A; objects of type A reference objects of type B; CacheB
> references objects of type B. I would like to guarantee that weak
> references in CacheB are not flushed unless the corresponding reference
> from CacheA is first flushed. I assume will be the case if a non-weak
> reference from A to B is maintained. Can anyone verify?

Weak pointers are useful for data that should be shared by several
independent "users" and discarded when the number of users drops to zero.

I wouldn't call your CacheB a cache if it is a weak array or a weak hash
table. It is a table of shared objects. These objects of type B are
shared by objects of type A and possibly other users of CacheB.



Martin

-- 
http://mjambon.com/


  reply	other threads:[~2008-10-31  2:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-30 18:19 Warren Harris
2008-10-31  2:14 ` Martin Jambon [this message]
2008-10-31  8:37   ` [Caml-list] " Daniel Bünzli
2008-10-31 14:57     ` Martin Jambon
2008-10-31 15:27       ` Daniel Bünzli
2008-10-31 16:52         ` Martin Jambon
2008-10-31 19:12       ` Aleksey Nogin
2008-10-31 20:10         ` Martin Jambon
2008-10-31 20:44         ` Martin Jambon

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=490A6A19.9050704@ens-lyon.org \
    --to=martin.jambon@ens-lyon.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=warren@metaweb.com \
    /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).