From: Nuutti Kotivuori <naked+caml@naked.iki.fi>
To: Olivier Andrieu <andrieu@ijm.jussieu.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Object-oriented access bottleneck
Date: Tue, 09 Dec 2003 15:53:52 +0200 [thread overview]
Message-ID: <87smju9jwv.fsf@naked.iki.fi> (raw)
In-Reply-To: <16341.52076.429385.418402@akasha.ijm.jussieu.fr> (Olivier Andrieu's message of "Tue, 9 Dec 2003 14:17:32 +0100")
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
next prev parent reply other threads:[~2003-12-09 13:53 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-07 2:39 Nuutti Kotivuori
2003-12-07 2:59 ` Nicolas Cannasse
2003-12-07 11:22 ` Benjamin Geer
2003-12-07 14:12 ` Nicolas Cannasse
2003-12-07 18:04 ` Nuutti Kotivuori
2003-12-07 10:27 ` Jacques Garrigue
2003-12-07 19:46 ` Nuutti Kotivuori
2003-12-08 1:07 ` Jacques Garrigue
2003-12-08 15:08 ` Nuutti Kotivuori
2003-12-08 15:42 ` Richard Jones
2003-12-09 0:26 ` Nicolas Cannasse
2003-12-09 12:10 ` Nuutti Kotivuori
2003-12-09 13:17 ` Olivier Andrieu
2003-12-09 13:53 ` Nuutti Kotivuori [this message]
2003-12-08 17:51 ` Brian Hurt
2003-12-08 18:19 ` brogoff
2003-12-08 20:09 ` Brian Hurt
2003-12-08 19:02 ` Xavier Leroy
2003-12-08 21:37 ` Brian Hurt
2003-12-08 21:06 ` Nuutti Kotivuori
2003-12-08 22:30 ` malc
2003-12-07 18:23 ` Brian Hurt
2003-12-07 18:14 ` Nuutti Kotivuori
2003-12-07 19:30 ` Brian Hurt
2003-12-07 23:50 ` Abdulaziz Ghuloum
2003-12-08 17:29 ` Brian Hurt
2003-12-08 18:48 ` Nuutti Kotivuori
2003-12-08 10:17 ` Nuutti Kotivuori
2003-12-08 19:51 ` skaller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87smju9jwv.fsf@naked.iki.fi \
--to=naked+caml@naked.iki.fi \
--cc=andrieu@ijm.jussieu.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox