Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSInvocation question



On Feb 21, 2008, at 11:18 PM, Chris Suter wrote:

I'm not sure what exactly you're trying to do, but NSInvocation isn't that fast a way of making a call. It's certainly going to somewhat slower than a compiler generated call and it's not NSInvocation's intended use.

I should have realized that when NSInvocation started giving me trouble...


If you want fast calls, you should use -[NSObject methodSelector:], cache the result and then call it directly with whatever arguments you want. Make sure you read the documentation to see an example as it usually requires a cast.

Having said that, let me say what has been said many times before, unless you know it's going to be a performance bottleneck, you should be writing your code so that it's as readable/maintainable as possible and then optimise for performance if necessary.

The nice thing about NSInvocation is not so much its efficiency (or lack thereof, as the case may be), but the fact that once you've got the thing constructed, you can just call invoke on it, without having to think about what's inside. I have functions of zero, one, or two arguments that I wrapped up in NSInvocations. With IMPs, I have to check the number of arguments both for the typing and for the call.


However, even with the check for number of arguments, an IMP is very very fast.

Thanks!

Hank

Hank Heijink
email@hidden



_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >NSInvocation question (From: Hank Heijink <email@hidden>)
 >Re: NSInvocation question (From: Nir Soffer <email@hidden>)
 >Re: NSInvocation question (From: Hank Heijink <email@hidden>)
 >Re: NSInvocation question (From: Chris Suter <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.