Re: ObjC in time-critical parts of the code
Re: ObjC in time-critical parts of the code
- Subject: Re: ObjC in time-critical parts of the code
- From: Justin Carlson <email@hidden>
- Date: Sun, 18 Jan 2009 20:56:47 -0600
On Jan 18, 2009, at 7:36 PM, Greg Titus wrote:
On Jan 18, 2009, at 5:13 PM, Justin Carlson wrote:
Jean-Daniel Dupas wrote:
>
> Each time you use KVC/KVO.
Hi Jean-Daniel,
Sorry if I misreading this, your response was short - it could mean
a few things. I am inclined to think you were responding to my
question "how often do your subclasses rewrite getters/setters?".
Justin,
Jean-Daniel was referring to the way that Apple has implemented
automatic KVO compatibility. The first time that someone tries to
observe an object of class X with accessor -foo, and -setFoo:, the
framework makes a dynamic subclass of your class X called something
like X_KVO, and reimplements -setFoo: to be something like:
- (void)setFoo:(id)aFoo
{
[self willChangeValueForKey:@"foo"];
[super setFoo:aFoo];
[self didChangeValueForKey:@"foo"];
}
It then replaces the original X class with the X_KVO class (using a
mechanism like -poseAs:) so that all existing X's are now X_KVO's.
This automatic and dynamic subclassability of getters/setters makes
KVO a lot easier to use, because a lot of it happens for you without
any effort on the programmer's part. And, of course, this wouldn't
be possible had the setter been defined non-virtually in a language
like C++. So here's an example of the dynamism being useful for even
the smallest and simplest of methods (that would normally be inlined
in a C++ framework design).
Hope this helps,
- Greg
Hi Greg,
Thank you for clarifying Jean-Daniel's response. ObjC has nice
features, strengths, and conveniences; neither I nor Scott tried to
make that argument against ObjC. Unfortunately, this mechanism does
not compare to the alternatives in performance critical zones - where
the 'free' interface is usually overkill for member access. I'm not
saying that it is not a necessary ingredient to the mechanics of KVC/
KVO, just that there are better alternatives in performance critical
zones.
Regards,
J
_______________________________________________
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