English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Re: Constants immediatelly disappear from the Weak array. (PR#1925)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-11-12 (12:48)
From: Damien Doligez <damien.doligez@i...>
Subject: [Caml-list] Re: Constants immediatelly disappear from the Weak array. (PR#1925)
On Wednesday, November 12, 2003, at 10:13 AM, Aleksey Nogin wrote:

> When trying to switch from 3.06 to 3.07+2 I've noticed the following 
> difference in how the Weak module works:

   In 3.06, an empty list [] does not disappear from a weak array;
   in 3.07+2 it disappears immediately

> Basically, in 3.07+2, the empty list disappears from the weak array as 
> soon as it is added into it. Is this a bug or a feature?


> The old behavior is useful because it allows to assume that while a 
> value is referenced somewhere, Weak.get will always return Some. This 
> allowed using Weak.get as an indicator of whether it was OK to discard 
> some "helper" data (which should be only discarded after the primary 
> data is no longer in use).

Yes, but.  In 3.06, [] will never be removed from the weak array, and
you will keep your helper data forever.

The source your the problem is that [] is not allocated in the heap.
It is represented by an integer value.  Hence, there is no sharing
between various occurrences of [] in your data and the notion of a
weak pointer to [] does not make sense.

If you really want to make sure that you are manipulating pointers,
you should use a record or a list ref.

-- Damien

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners