caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Dr. Thomas Fischbacher" <t.fischbacher@soton.ac.uk>
To: Alain Frisch <alain@frisch.fr>
Cc: dmitry grebeniuk <gds-mlsts@moldavcable.com>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Memory statistics tool
Date: Thu, 24 Jul 2008 16:44:58 +0100	[thread overview]
Message-ID: <4888A37A.5090407@soton.ac.uk> (raw)
In-Reply-To: <48889C59.8080806@frisch.fr>

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 = (==)
>>>end);;
>>
>>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
t.fischbacher@soton.ac.uk



  reply	other threads:[~2008-07-24 15:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-23 10:54 Dr. Thomas Fischbacher
2008-07-23 11:47 ` [Caml-list] " Daniel Bünzli
2008-07-23 12:40   ` Jan Kybic
2008-07-23 12:44 ` dmitry grebeniuk
2008-07-23 13:09   ` Dr. Thomas Fischbacher
2008-07-23 13:16     ` Alain Frisch
2008-07-24 12:48       ` Dr. Thomas Fischbacher
2008-07-24 15:14         ` Alain Frisch
2008-07-24 15:44           ` Dr. Thomas Fischbacher [this message]
2008-07-24 16:12             ` Alain Frisch

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=4888A37A.5090407@soton.ac.uk \
    --to=t.fischbacher@soton.ac.uk \
    --cc=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=gds-mlsts@moldavcable.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).