• 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: "Frederick C. Lee" <email@hidden>
  • Date: Fri, 10 Feb 2006 17:14:07 -0800

I wasn't thinking about overhead when writing ObjC code.
I do a lot of [self <routine>] calls within my .m codes.

These internal calls would more-efficiently be made using C routines instead.
The ObjC routines could then be used for accessors instead, particularly called
from outside the class; or interfacing with the GUI/Controllers.


Ric.


On Feb 10, 2006, at 4:52 PM, David Hart wrote:

The overhead isn't so much in the parameter passing per say - but the method
invocation as a whole. With a straight C function call, you essentially just
need to branch + stack setup and tear down; with obj-c dynamic method
invocation, for example [obj foo] is really a call to objc_msg_send (or
objc_msg_sendv) with the object id, the selector and arguments as
parameters. Then objc_msg_send will locate the function address from the
selector, and branch to that + stack setup and teardown... So... Basically
it comes down to this:


Straight C:
function call is branch + stack setup and teardown/paramater passing

Objective-C:
Method invocation is function call to objc_msg_send + normal function call
overhead; so two times the function call overhead + the work objc_msg_send
does to look up the appropriate function based on the selector.


This is a bit of a simplification, but is basically it, and after having
said all of that... The overhead of a obj-c method is really a non- issue for
MOST code...


PS there are ways to speed up objc method invocation with caching of method
addresses, and i think the runtime has some caching of its own...
_______________________________________________
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: Greg Titus <email@hidden>
  • Prev by Date: Re: ObjC procedure vs C procedure within Cocoa
  • Next by Date: Re: Is C's parameter passing more-efficient than ObjC's message passing?
  • 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