From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 9FB30BBAF for ; Mon, 20 Apr 2009 08:14:35 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtEBAMOv60nZSMDqi2dsb2JhbACBTpRtAQEBCgsKBw8FtQSDfQY X-IronPort-AV: E=Sophos;i="4.38,431,1233529200"; d="scan'208";a="27942152" Received: from fmmailgate03.web.de ([217.72.192.234]) by mail1-smtp-roc.national.inria.fr with ESMTP; 20 Apr 2009 08:14:35 +0200 Received: from smtp07.web.de (fmsmtp07.dlan.cinetic.de [172.20.5.215]) by fmmailgate03.web.de (Postfix) with ESMTP id 2174CFA98A1E; Mon, 20 Apr 2009 08:14:35 +0200 (CEST) Received: from [78.43.226.218] (helo=frosties.localdomain) by smtp07.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #277) id 1Lvmm2-0003C9-00; Mon, 20 Apr 2009 08:14:34 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1Lvmm2-0005gw-E7; Mon, 20 Apr 2009 08:14:34 +0200 From: Goswin von Brederlow To: Guillaume Hennequin Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] mixed functional / object style References: Date: Mon, 20 Apr 2009 08:14:34 +0200 In-Reply-To: (Guillaume Hennequin's message of "Sat, 18 Apr 2009 16:48:23 +0200") Message-ID: <87tz4jvol1.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.21 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1/O6PP9M5YyHR3CDvhdtM5qQJfuLAstI7R7h2uI mfLwGg+pZuJHlbs5DN1+tUzDa7uaLhuq/nMWRqY1jyoyZsvgp/ Zffwv8ecM= X-Spam: no; 0.00; guillaume:01 val:01 mutable:01 val:01 mutable:01 guillaume:01 byte:01 const:01 mfg:98 caml-list:01 writes:01 define:02 define:02 functional:02 variables:02 Guillaume Hennequin 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