Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Damien Doligez <damien.doligez@inria.fr>
To: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] memory leak in toplevel? or, how to implement sizeof
Date: Fri, 7 Jan 2011 13:25:42 +0100	[thread overview]
Message-ID: <7577E373-EB25-4A7E-90C1-30491F27B4F9@inria.fr> (raw)
In-Reply-To: <20110106145924.GE12229@vaio.hsd1.pa.comcast.net>


On 2011-01-06, at 15:59, Jim Pryor wrote:

> Actually I think the overhead should be 22. Making it 22 gives these
> sensible results:

The overhead is exactly the heap space used by the value returned by
Gc.stat.  In your case it is 23 words, not 22.

>    # sizeof (fun x -> x) 10;;
>    - : int * int = (1, 10)
> 
> That is, one word for the int.

The int is not allocated in the heap, so the result should be 0.

It is best to let ocaml compute the overhead, because it will be different
on 32- and 64-bit machines:

  let overhead =
    let first = Gc.((stat()).minor_words) in
    let second = Gc.((stat()).minor_words) in
    int_of_float (second -. first)
  ;;

-- Damien


  reply	other threads:[~2011-01-07 12:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-06 13:05 Jim Pryor
2011-01-06 14:20 ` David Allsopp
2011-01-06 14:44   ` Jim Pryor
2011-01-06 14:59     ` Jim Pryor
2011-01-07 12:25       ` Damien Doligez [this message]
2011-01-07 14:14         ` Jim Pryor
2011-01-07 14:22           ` dmitry grebeniuk
2011-01-06 15:05     ` Pascal Zimmer

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=7577E373-EB25-4A7E-90C1-30491F27B4F9@inria.fr \
    --to=damien.doligez@inria.fr \
    --cc=caml-list@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