Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 233667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:07:18+00:00 2026-05-11T20:07:18+00:00

I am just staring to play around with Objective C (writing toy iPhone apps)

  • 0

I am just staring to play around with Objective C (writing toy iPhone apps) and I am curious about the underlying mechanism used to dispatch messages. I have a good understanding of how virtual functions in C++ are generally implemented and what the costs are relative to a static or non-virtual method call, but I don’t have any background with Obj-C to know how messages are sent. Browsing around I found this loose benchmark and it mentions IMP cached messages being faster than virtual function calls, which are in turn faster than a standard message send.

I am not trying to optimize anything, just get deeper understanding of how exactly the messages get dispatched.

  • How are Obj-C messages dispatched?
  • How do Instance Method Pointers get cached and can you (in general) tell by reading the code if a message will get cached?
  • Are class methods essentially the same as a C function (or static class method in C++), or is there something more to them?

I know some of these questions may be ‘implementation dependent’ but there is only one implementation that really counts.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:07:18+00:00Added an answer on May 11, 2026 at 8:07 pm

    How are Obj-C messages dispatched?

    Objective-C messages are dispatched using the runtime’s objc_msgSend() function. Shown in the Apple docs, the function takes at least 2 arguments:

    1. The receiving object
    2. The selector of the message
    3. [A variable list of arguments to the message being sent.]

    Instances of a class have an isa pointer, which is a pointer to their class object. The selectors of methods in each object are stored in a "table" in the class object, and the objc_msgSend() function follows the isa pointer to the class object, to the find this table, and checks whether the method is in the table for the class. If it cannot find it, it looks for the method in the table of the class’s superclass. If not found, it continues up the object tree, until it either finds the method or gets to the root object (NSObject). At this point, an exception is thrown.

    How do Instance Method Pointers get cached and can you (in general) tell by reading the code if a message will get cached?

    From Apple’s Objective-C runtime guide on Messaging:

    To speed the messaging process, the runtime system caches the selectors and addresses of methods as they are used. There’s a separate cache for each class, and it can contain selectors for inherited methods as well as for methods defined in the class. Before searching the dispatch tables, the messaging routine first checks the cache of the receiving object’s class (on the theory that a method that was used once may likely be used again). If the method selector is in the cache, messaging is only slightly slower than a function call. Once a program has been running long enough to “warm up” its caches, almost all the messages it sends find a cached method. Caches grow dynamically to accommodate new messages as the program runs.

    As stated, caching starts to occur once the program is running, and after the program has been running long enough, most of the method calls will run through the cached method. As it also says, the caching occurs as the methods are used, so a message is only cached when it is used.

    Are class methods essentially the same as a C function (or static class method in C++), or is there something more to them?

    Class objects handle method despatch in a similar manner to that of instances of classes. Each class object has an object that stores its own class methods, in an object called a metaclass. The class object has its own isa pointer to its metaclass object, which in turn has super metaclass objects, which it can inherit class objects from. Method dispatch to class methods is as so:

    1. The dispatch system follows the class object’s isa pointer to the metaclass object
    2. The metaclass object’s method table is searched for the class method.
    3. If not found, the search continues to the metaclass object’s superclass, where the search continues.
    4. This process repeats until either the method is found, or until it gets to the root metaclass, and an exception is thrown.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just starting to play around with directx and I've read a few articles
I'm just starting to play around with GTK+ and I wanted to stop bad
I'm new to the Entities Framework, and am just starting to play around with
I'm just starting to play around with Google Guice as a dependency injection framework
I am just beginning to play around with .NET (using C#). Which namespace, aside
today I just tried to play a little bit around with the opcodes in
I'm just starting to play around with Geektool and applescripting to make my mac
I just started to play around with MongoDB (C#) and tried to port a
I'm just starting to play around with the android SDK, and was trying to
I am just starting to play with nservice bus and am trying to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.