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
Memory statistics tool
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-07-24 (15:45)
From: Dr. Thomas Fischbacher <t.fischbacher@s...>
Subject: Re: [Caml-list] Memory statistics tool
Alain Frisch wrote:

>>>As long as the data structure supports the polymorphic hash function, it
>>>should work to simply use a regular hash table with the polymorphic hash
>>>function and physical equality, as in:
>>>module S = Hashtbl.Make(struct
>>>   type t = Obj.t
>>>   let hash = Hashtbl.hash
>>>   let equal = (==)
>>Why? (I.e. I'm not convinced yet.)
> The two functions (hash and equal) are invariant w.r.t. changes of
> physical memory location of their arguments.

The OCaml manual gives no guarantee that Hashtbl.hash does not cons, so
I cannot assume this. Now, without that guarantee, there is a nasty race
condition in which the determination of the hash bucket causes objects
to move in memory. But still, we are safe, as we are just testing for
equality, and the hash bucket does not depend on the memory address,
but on the substructure of the hashed entity.

So, ok, you convinced me.

Anyway, it works now -- thanks to Dmitry's code, I can now do
things like...:

tf@alpha:~/ocaml$ nsim_i

In [1]: ocaml.memory_footprint(ocaml.make_element("E",[3],3,1))
Out[1]: (154.0, 49.0, 5.0)

In [2]:

...and use the interactive Python toplevel of our micromagnetic
simulator "nmag" to find out how much memory is used by the OCaml
data structures under the hood. Excellent. Thanks, Dmitry!

best regards,
Thomas Fischbacher