From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA07709; Tue, 9 Dec 2003 14:53:56 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA06833 for ; Tue, 9 Dec 2003 14:53:55 +0100 (MET) Received: from smtp1.pp.htv.fi (smtp1.pp.htv.fi [212.90.64.119]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hB9Drsr00277 for ; Tue, 9 Dec 2003 14:53:54 +0100 (MET) Received: from posti.pp.htv.fi (posti.pp.htv.fi [212.90.64.50]) by smtp1.pp.htv.fi (Postfix) with ESMTP id 74DF98031B; Tue, 9 Dec 2003 15:53:54 +0200 (EET) Received: from oro (aka.pp.htv.fi [213.243.183.115]) by posti.pp.htv.fi (8.11.1 (Revision 1.5+JAGae91741+JAGae92668) /8.11.1) with ESMTP id hB9DrrT23907; Tue, 9 Dec 2003 15:53:53 +0200 (EET) Received: from naked by oro with local (Exim 3.36 #1 (Debian)) id 1ATiJE-0006Wy-00; Tue, 09 Dec 2003 15:53:52 +0200 To: Olivier Andrieu Cc: caml-list@inria.fr Subject: Re: [Caml-list] Object-oriented access bottleneck References: <871xrhe4hb.fsf@iki.fi> <20031207192702D.garrigue@kurims.kyoto-u.ac.jp> <87brqkcsxf.fsf@iki.fi> <20031208100725E.garrigue@kurims.kyoto-u.ac.jp> <87llpnbb4d.fsf@iki.fi> <20031208154244.GA20491@redhat.com> <006901c3bdeb$252ff510$0274a8c0@PWARP> <878ylmb3a8.fsf@naked.iki.fi> <16341.52076.429385.418402@akasha.ijm.jussieu.fr> From: Nuutti Kotivuori Date: Tue, 09 Dec 2003 15:53:52 +0200 In-Reply-To: <16341.52076.429385.418402@akasha.ijm.jussieu.fr> (Olivier Andrieu's message of "Tue, 9 Dec 2003 14:17:32 +0100") Message-ID: <87smju9jwv.fsf@naked.iki.fi> User-Agent: Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Portable Code, linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 bottleneck:01 andrieu:01 inlined:01 statically:01 foo:01 val:01 val:01 foo:01 trickery:01 unsafe:01 ocaml:01 caml:01 caml:01 inherit:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Olivier Andrieu wrote: > What are you talking about ? The Obj module and in particular > Obj.set_field is about modifying caml values (records, variants, > tuples, whatever), not caml objects. Yes, this is understood. > Access to instance variable in objects is not inlined because you > can't statically known in which slot is the variable. Ex: > > class foo = object val x = 0 end > class bar = object val y = 1 inherit foo end > > In an object foo, x is in slot 0, but in an object bar, x is in slot > 1. (Actually that's not 0 and 1 but 2 and 3 because the object > stores other stuff in the first two slots). Yes, quite so. But if we _do_ know the exact implementation of the object, and we know in which order the variables in the object are, we can *abuse* Obj.set_field to manipulate those values directly. So that's about as close to the definition of unsafe as you can get. As for your example about inheriting - there would have to be quite some trickery to be done to be able to this working with inheritance. In C++, with equivalent declarations, a typecast from bar pointer to a foo pointer actually returns a different pointer value - one that is at the start of class foo inside bar. This obviously wouldn't work in OCaml, because of the block headers and all that. -- Naked ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners