• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is C's parameter passing more-efficient than ObjC's message passing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is C's parameter passing more-efficient than ObjC's message passing?


  • Subject: Re: Is C's parameter passing more-efficient than ObjC's message passing?
  • From: Erik Buck <email@hidden>
  • Date: Fri, 10 Feb 2006 20:36:43 -0500

Interesting.
When you say, 'no message passing overhead with a straight c
function...'

Are you saying that C's parameter passing is *more efficient* than
ObjC's message passing?

void doAlphaRects(CGContextRef context) {...}  vs
- (void) doAlphaRects:(CGContextRef) context) {....}


Don't worry about it! If you are not aware of the different implementations between C function calls and Objective-C message passing then any attempt to select one over the other for performance reasons is almost surely premature optimization and misguided.


Here's a random handful of references to premature optimization:
http://www.cookcomputing.com/blog/archives/000084.html
http://www.flounder.com/optimization.htm
http://billharlan.com/pub/papers/ A_Tirade_Against_the_Cult_of_Performance.html
http://www.devx.com/tips/Tip/13844


If you are just academically curious how Objective-C message sending is implemented and how it compares to C function calls, I suggest "How Messaging Works"
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ Articles/chapter_4_section_6.html
http://www.mulle-kybernetik.com/artikel/Optimization/


and in particular
http://www.mulle-kybernetik.com/artikel/Optimization/opti-3.html.

Finally, you can convert any Objective-C message into a function call using the Objective-C IMP type.
See -methodForSelector:
From the docs:
"methodForSelector:
Locates and returns the address of the receiver’s implementation of the aSelector method so it can be called as a function.


- (IMP)methodForSelector:(SEL)aSelector

Discussion

If the receiver is an instance, aSelector should refer to an instance method; if the receiver is a class, it should refer to a class method.

The aSelector selector must be a valid, non-NULL selector. If in doubt, use the respondsToSelector: method to check before passing the selector to methodForSelector:.

See "Selectors" for a description of the IMP and SEL types, and how to invoke the returned method implementation.

See Also

+ instanceMethodForSelector:"

http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ Articles/chapter_4_section_8.html
http://developer.apple.com/documentation/Performance/Conceptual/ CodeSpeed/Articles/CriticalCode.html


From the docs:
"Important: Caching IMP pointers should be done only if you have measured a specific performance problem in a critical loop. In most situations, caching pointers is unnecessary and can make your application hard to maintain by inhibiting the dynamic nature of the Cocoa runtime system."


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Is C's parameter passing more-efficient than ObjC's message passing?
      • From: Charlton Wilbur <email@hidden>
  • Prev by Date: Re: Objective-C++, class scope constants, name conflicts
  • Next by Date: Re: Objective-C++, class scope constants, name conflicts
  • Previous by thread: Re: Is C's parameter passing more-efficient than ObjC's message passing?
  • Next by thread: Re: Is C's parameter passing more-efficient than ObjC's message passing?
  • Index(es):
    • Date
    • Thread