Guillaume Hennequin <gje.henneq...@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 _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs