From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA13426 for caml-redistribution; Mon, 6 Sep 1999 10:26:15 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA27693 for ; Sat, 4 Sep 1999 16:31:10 +0200 (MET DST) Received: from lena.cs.utu.fi (lena.cs.utu.fi [130.232.75.62]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id QAA15125; Sat, 4 Sep 1999 16:31:08 +0200 (MET DST) Received: from lena.cs.utu.fi ([130.232.75.62]:33420 "HELO lena.cs.utu.fi" ident: "SOCKFAULT1") by lena.cs.utu.fi with SMTP id <40786-330>; Sat, 4 Sep 1999 17:26:33 +0300 Date: Sat, 4 Sep 1999 17:26:33 +0300 (EET DST) From: Nicolas Ollinger To: Jerome Vouillon cc: caml-list@inria.fr Subject: Re: Efficency in OCaml In-Reply-To: <19990902010939.12962@pauillac.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis On Thu, 2 Sep 1999, Jerome Vouillon wrote: > On Wed, Sep 01, 1999 at 02:40:21PM -0400, chet@watson.ibm.com wrote: > > Is there a description of the Ocaml object and > > "virtual-function-table" format? (snip description of buckets use) I played a little with objects representation in OCaml 2.xx. As far as I understand, at least in bytecode, class instances are represented as boxed values tagged object_tag with n+2 fields : then first field is the method array array described by Jerome in last mail, the second field seems to be a unique id associate to the object, other fields are used for instance variables in the order of declaration, inherited variables first. As the method array array is unique for each class, it can be used to identify the class (notice that classes are represented as global variables). I'm intrigued by this second field, what is the use of this id ? Where is the necessity to identify uniquely every object ? Concerning marshaling of objects, a simple solution is to use a function like: let crunch o = let r = Obj.dup (Obj.repr o) in let idclass = compute_id (Obj.field r 0) in Obj.set_field r 1 idclass; Obj.set_tag r Obj.marshaled_object_tag r;; with compute_id a function that deduce a unique class id of the object. Then unmarshaling is just doing the inverse operation. Of course, if you want to share objects between different programs then you must add some informations about the module in which the class is declared, and so one. Any comment ? N. --