caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: OCaml Mailing List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] understanding weak
Date: Fri, 31 Oct 2008 21:10:52 +0100	[thread overview]
Message-ID: <490B664C.7000209@ens-lyon.org> (raw)
In-Reply-To: <490B58BA.6090307@metaprl.org>

Aleksey Nogin wrote:
> On 31.10.2008 07:57, Martin Jambon wrote:
> 
>> let x = (1, 2);;
>> let wa = Weak.create 10;;
>> Weak.set wa 0 (Some x);;
>> ...
>> print_int (fst x);;
>>
>> (fst x) would certainly cause funny effects if x were GC'ed at an
>> arbitrary time after it has been added to the weak array.
>>
>> An object can be reclaimed by the GC only if there is no reference to
>> it. This remains true. Adding an object to a weak array just doesn't
>> count as a reference.
>>
> Martin,
> 
> You are answering the wrong question - you are answering "could x be
> GCed too early?" - the answer is obviously "no". However, the initial
> question was "could (Some x) be removed from wa too early by GC - before
> x is orphaned?" The answer is "we'd hope not", but the documentation is
> somewhat ambiguous.

OK. I think now I understand the question :-)
And we all agree that the documentation could be clearer.

What I'm wondering is why there is one Weak.set function that takes an
option as argument rather than a pair Weak.set/Weak.clear.

What is certain is that some (re)boxing is done by Weak.get:

# let a = Weak.get wa 0;;
val a : (int * int) option = Some (1, 2)
# let b = Weak.get wa 0;;
val b : (int * int) option = Some (1, 2)
# a == b;;
- : bool = false

Of course it doesn't tell whether the original (Some x) is stored as-is
but copied by Weak.get or if x is stored unwrapped.

I think I'll just take a look at the implementation. That can only be a
good thing.


Martin
-- 
http://mjambon.com/


  reply	other threads:[~2008-10-31 20:18 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 ` [Caml-list] " Martin Jambon
2008-10-31  8:37   ` 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 [this message]
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=490B664C.7000209@ens-lyon.org \
    --to=martin.jambon@ens-lyon.org \
    --cc=caml-list@yquem.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).