Re: Cocoa et al as HCI usability problem
Re: Cocoa et al as HCI usability problem
- Subject: Re: Cocoa et al as HCI usability problem
- From: Greg Titus <email@hidden>
- Date: Mon, 19 May 2008 11:10:05 -0700
On May 19, 2008, at 10:52 AM, David Wilson wrote:
On Mon, May 19, 2008 at 1:33 PM, Peter Duniho <email@hidden>
wrote:
Maybe I'm misinformed about how message-dispatching in Objective-C
works.
But AFAIK, it's nothing like the direct invocation and v-table
mechanisms
that exist in C# and Java. It's the exact opposite of "similar".
You're misinformed about how message-dispatching in Objective-C works.
It's very analogous to a v-table in c++ and related languages; I
believe there's just a touch more run-time information stored in the
table.
Well, "similar" and "analogous" and "touch more information" are all
kind of vague words, and we can disagree on wether they are analogous
or similar or not. I don't think the mechanisms are very similar at
all. To nail things down:
A v-table implementation means that the class of an object contains an
array of function pointers. A call to a method compiles down to "call
function #3". This means that both the caller and the callee both need
to know the mapping that virtual method foo() is the third item in the
v-table. Which means that the caller needs to be able to see all the
class information for the receiver and all superclasses of the
receiver to perform that mapping. Changing the order or number of
virtual methods in any superclass results in all code that calls
methods on that class needing to be recompiled because the v-table
indices change. The benefit is that at runtime this simple index
lookup then call is very fast.
Objective-C uses a method dispatch hash table. A method name is
converted to something called a selector at compile time, and that
selector is a unique one-to-one mapping to the method name. (So there
is a "foo" selector with some unique value and at runtime you can
convert the selector to the method name and vice versa.) The class of
an object contains a hash table that allows you to look up a function
pointer based on a selector. A call to a method compiles down to "look
up selector X in this object's hash table and call it". The linker
performs the uniquing of method names to selectors, so when compiling
the caller doesn't need to know anything at all about the class of the
receiver. The penalty to all this flexibility is that at runtime the
hash table lookup isn't quite as fast as the v-table simple index.
Hope this helps,
- Greg
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden