caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: [Caml-list] Classes and memory foodprint + speed
Date: Sun, 26 Dec 2010 14:57:18 +0100	[thread overview]
Message-ID: <87bp48ab7l.fsf@frosties.localnet> (raw)

Hi,

I want my classes to have some "variables" and there seem to be multiple
ways to do this. So I'm wondering what the actual difference is for the
memory foodprint and speed. So lets look at a trivial example:

# class foo (init_x : int) = object val x = init_x method get_x = x end
  class bar (init_x : int) (init_y : int) = object inherit foo init_x
val y = init_y method get_y = y end
  let t = new bar 1 2;;

  class foo : int -> object val x : int method get_x : int end
class bar :
  int ->
  int ->
  object val x : int val y : int method get_x : int method get_y : int end
val t : bar = <obj>


# class foo (x : int) = object method get_x = x end
  class bar (x : int) (y : int) = object inherit foo x method get_y = y
end
  let t = new bar 1 2;;

  class foo : int -> object method get_x : int end
class bar : int -> int -> object method get_x : int method get_y : int end
val t : bar = <obj>


So what are the differences between the two? How are they represented in
memory and how does that affect speed? Does it make sense to have "val
x" if it isn't mutable?

MfG
        Goswin

                 reply	other threads:[~2010-12-26 13:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=87bp48ab7l.fsf@frosties.localnet \
    --to=goswin-v-b@web.de \
    --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;
as well as URLs for NNTP newsgroup(s).