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 9120071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:32:49+00:00 2026-06-17T05:32:49+00:00

my question as the title says.obviously, the first parameter was used for this pointer

  • 0

my question as the title says.obviously, the first parameter was used for this pointer , in some taste of c++.what about the second one? thak you.

  • 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-06-17T05:32:50+00:00Added an answer on June 17, 2026 at 5:32 am

    The signature of objc_msgSend() is:

    id objc_msgSend(id self, SEL op, ...);
    

    Every method call is compiled down to a call to this function. I.e., if you call:

    [anArray objectAtIndex:42];
    

    That will be compiled as if it were:

    objc_msgSend(anArray, @selector(objectAtIndex:), 42);
    

    Now, to your question, why do methods get compiled down to a function that has the SEL as the second argument. Or, more specifically, why is this method:

    - (id)objectAtIndex:(NSUInteger)index;
    

    Exactly equivalent to this C function:

    id object_at_index(id object, SEL _cmd, NSUInteger index);
    

    The answer is speed speed speed.

    Speed

    Specifically, by doing this, then objc_msgSend() never has to rewrite the stack frame* and it can also use a tail call optimization to jump directly to the method invocation. This is the same reason why you never see objc_msgSend() in backtraces in the debugger (save for when you actually crash/break in the messenger).

    objc_msgSend() uses the object and the _cmd to look up the implementation of the method and then, quite literally, jumps to that implementation.

    Very fast. Stack frame untouched.

    And, as others have stated, having _cmd around in the method implementation can be handy for a variety of reasons. As well, it also means that the messenger can do neat tricks like proxy support via NSInvocation and the like.

    *rewriting the stack frame can be insanely complex and expensive. Some of the arguments might be in registers some of the time, etc… All architecture dependent ABI nastiness. One of the biggest challenges to writing things like imp_implementationWithBlock() was figuring out how to do so without touching the stack because doing so would have been too slow and too bloated to be viable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question title just about says it all. I have a ASP.NET MVC 2
I recently asked just about the same question, but this one got a little
As the title says. Related to this question. Why does the following code not
It's my first question but I'm trying to ask correctly. As the title says
First: apologies for the question title, I don't actually know what the problem is
The title pretty much says it all. When I'm doing some reflection through my
I have a quick question. As the title says, I'd like to find a
I've searched for at question like this and i dont think there are one.
Question is simple and asked in the title. C# 4.0 Specification says: (§4.2.2) The
Question title says quite the whole. Anyway, let me be a little more precise.

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.