caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: Guillaume Hennequin <gje.hennequin@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] mixed functional / object style
Date: Mon, 20 Apr 2009 08:14:34 +0200	[thread overview]
Message-ID: <87tz4jvol1.fsf@frosties.localdomain> (raw)
In-Reply-To: <d8e32b760904180748h25b5dc06t3e204fbdc8caafde@mail.gmail.com> (Guillaume Hennequin's message of "Sat, 18 Apr 2009 16:48:23 +0200")

Guillaume Hennequin <gje.hennequin@gmail.com> writes:

> Dear list,
> this is a somewhat naive question
> let's define
> class a = object
>  val mutable v = ...
>  method v = v
>  method m = something that uses v
> end ;;
> now assume that I want to create a lot of those a objects, so many that I may
> encounter memory problems.
> I thought the following would be better, memory wise, but when I test it
> doesn't seem to be the case
> class a = object
>  val mutable v = ...
>  method v = v
> end ;;
> and instead of each object having its own method m, I define it separately
> let m x = something that calls x#v
> This question is somewhat equivalent to: what is the memory consumption of a
> simple method
> method m = let _ = self#v in () ??
> Thanks a lot
> Guillaume.

A class is a reference to the virtual table of a class and its
instance variables. There is exactly one virtual table for every class
you declrare and all instances of that class share the same virtual
table. All the methods are listed in that one virtual table.

So a method will cost you 4 or 8 byte (or maybe more, don't know how
big the entry for a method is) but it will be something small and
const no matter how many instances you have.

MfG
        Goswin


      parent reply	other threads:[~2009-04-20  6:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-18 14:48 Guillaume Hennequin
2009-04-20  5:34 ` [Caml-list] " Jacques Garrigue
2009-04-20  6:14 ` Goswin von Brederlow [this message]

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=87tz4jvol1.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=gje.hennequin@gmail.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).