• 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: NSPoint. The results. Look at that, Georg!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPoint. The results. Look at that, Georg!


  • Subject: Re: NSPoint. The results. Look at that, Georg!
  • From: Chris Hanson <email@hidden>
  • Date: Mon, 3 Mar 2003 10:11:24 -0600

At 12:49 AM +0900 3/4/03, Pascal Goguey wrote:
Yes, I just discovered that a few minutes ago.
Apparently _ALL_ objects have to inherit from NSObject, and
sizeof(NSObject) returns 4 bytes.

Not quite.

All Objective-C objects have an invisible isa pointer that refers to their class. This isa pointer is going to be sizeof(void*), which on 32-bit PowerPC is four bytes.

Objective-C doesn't support multiple inheritance, but it does support multiple root classes. FoundationKit actually uses this functionality, too.

Also, another poster said something to the effect that "all methods are virtual." This isn't quite true. In C++, virtual method dispatch resolves to the following pseudo-assembly:

C++: myObject->myMethod();

Asm: load vtable_offset(myObject),r4 // get vtable pointer into r4
load myMethod_offset(r4),r5 // get method pointer into r5
jsub r5 // jump to method

In the above, vtable_offset and myMethod_offset are compiler-generated constants. Method resolution in C++ still occurs at compile time, it's only method dispatch that's put off until runtime.

In contrast, Objective-C effectively looks up myMethod_offset at runtime, every time. (Just like Smalltalk and Self.) This is made fast using caching, and actually interacts better with the branch prediction & pipeline logic on modern processors than the C++ code above (or so I've heard a late-1990s paper from the Self project claims), but it's always going to be a higher cycle count than either C++ vtable dispatch or direct function dispatch.

-- Chris

--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Application Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: NSPoint. The results. Look at that, Georg! (From: Pascal Goguey <email@hidden>)

  • Prev by Date: Re: NSPoint. The results. Look at that, Georg!
  • Next by Date: RE: [Newbie] writing plain text to a file
  • Previous by thread: Re: NSPoint. The results. Look at that, Georg!
  • Next by thread: Re: NSPoint. The results. Look at that, Georg!
  • Index(es):
    • Date
    • Thread