Browse thread
[Caml-list] Object-oriented access bottleneck
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2003-12-09 (13:53) |
From: | Nuutti Kotivuori <naked+caml@n...> |
Subject: | Re: [Caml-list] Object-oriented access bottleneck |
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