Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 5. Messaging > Efficiency

Efficiency

You are probably saying to yourself: “All this look-up business has to be much slower than a plain function call.” It is. The runtime code goes to great lengths to make the method look up as fast as possible, but it is still slower than a C function call. However, this usually doesn’t make much practical difference. In almost every case, the time required to execute the body of a method will dwarf the time required to dispatch the message. There are rare cases where the dispatch overhead could be an issue. These are usually cases where you are doing something a huge number of times in a tight loop. If you find one of these cases, you can use the NSObject method methodForSelector: to get a pointer to the C function that implements the method:

IMP anIMP = [aShape methodForSelector: @selector( draw )];


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint