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
GC and map
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-05-15 (19:38)
From: Christophe Raffalli <christophe.raffalli@u...>
Subject: Re: [Caml-list] GC and map
Daniel Bünzli wrote:
> Can't you just use weak hash tables [1] in some way to implement that ?

In fact, to make it simpler, I want weak key functional map.

That is functional map where binding are GC-collected when the key is no 
more accessible by the GC. I did not present it this way, because this 
requires equal key to be physically equal which does not fit with 
functional map, but this is not a real problem in my case.

If I remember well previous investigations, it is tricky and ugly but 
possible to implement weak key imperative hash table from the poor weak 
array of OCaml.

But weak key functional map seems impossible (I have no proof ;-).

The use for that is to try it for an evaluator for a toy functional 
language where the key are variable names and the maps hold the value of 
the variables. I do not want to simplify maps by hand where some 
variables do not exists in specific closure and I had like the GC to do it.

Actually, this approach is not the one use in OCaml: when closures are 
build by OCaml, specific environments are build with only the required 
variables to make sure there is no memory leak. In my approach, you can 
share environments between many closures, but the scan of the 
environment by the GC is much more complex (not sure this is really a 
gain anyway)

> Best,
> Daniel
> [1] <http://caml.inria.fr/pub/docs/manual-ocaml/libref/Weak.html>