• 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: Inline C functions in Xcode 3
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inline C functions in Xcode 3


  • Subject: Re: Inline C functions in Xcode 3
  • From: Vincent Coetzee <email@hidden>
  • Date: Sun, 4 Nov 2007 04:57:12 +0200

Dear List,

The requirements of dynamic dispatch do NOT preclude the use of inline code. More advanced languages such as Self for example generate native machine code and aggressively inline code for performance reasons. In the case of Self, structures known as Polymorphic Inline Caches or PICS for short do various tests using very short native machine instructions to rapidly decide on the correct dispatch. The ordering of the tests and storage of the "classes" (although in the case of Self there are no classes only prototypes and sort of code level mixins called traits, and these are way more complicated than Objective-C's relatively linear class hierarchies) are constantly modified according to the relative incidence of invocations that pertain to that "class". This ensures that the most common cases have absolutely minimal dispatch overheads. Self as well as Smalltalk are both significantly more dynamic than Objective-C and manage wonderfully with considerable inline code. Dynamic dispatch and inlining are completely orthogonal issues.

Vincent

On 04 Nov 2007, at Sunday 04/11/200704:23 , Chris Hanson wrote:

On Nov 3, 2007, at 5:21 PM, Vincent Coetzee wrote:

This may also be off-topic and maybe I have missed this if it was covered earlier in the discussion but could someone explain to dumb little me why it is not possible to mark Objective-C methods as inline ?

It was not covered earlier, and would be more on-topic for the objc- language mailing list.


That said, Objective-C explicitly requires dynamic method dispatch, and all of Cocoa (and Mac OS X) builds atop this foundation. Thus there can't be such a thing in Objective-C as an "inline method" - it wouldn't be dispatched to dynamically, and therefore wouldn't be a method.

You can define inline functions that have access to instance variables very easily, however:

@interface MyClass : NSObject {
@private
 NSString *foo;
}
@end

@implementation MyClass

inline void LogFoo(MyClass *self) {
 NSLog(@"foo is %@", self->foo);
}

- (void)doSomething {
   LogFoo(self);
}

@end

The LogFoo function will be inlined if possible, and since it's defined within an @implementation block for a class, has access to the @protected and @private instance variables of instances of that class.

 -- Chris


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Inline C functions in Xcode 3
      • From: Jonas Maebe <email@hidden>
References: 
 >Inline C functions in Xcode 3 (From: David Riggle <email@hidden>)
 >Re: Inline C functions in Xcode 3 (From: Nick Zitzmann <email@hidden>)
 >Re: Inline C functions in Xcode 3 (From: Michael Nickerson <email@hidden>)
 >Re: Inline C functions in Xcode 3 (From: Eric Albert <email@hidden>)
 >Re: Inline C functions in Xcode 3 (From: Steve Checkoway <email@hidden>)
 >Re: Inline C functions in Xcode 3 (From: Vincent Coetzee <email@hidden>)
 >Re: Inline C functions in Xcode 3 (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: Xcode 3 SCM Preference Pane Documentation
  • Next by Date: Re: SenTesttingKit.framework runtime failure
  • Previous by thread: Re: Inline C functions in Xcode 3
  • Next by thread: Re: Inline C functions in Xcode 3
  • Index(es):
    • Date
    • Thread