• 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: KVO and accessors - are they needed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO and accessors - are they needed


  • Subject: Re: KVO and accessors - are they needed
  • From: "John C. Randolph" <email@hidden>
  • Date: Fri, 22 Oct 2004 12:52:53 -0700


On Oct 22, 2004, at 9:21 AM, Steven Kramer wrote:




Well, YMMV of course, but Keep in mind that when KVC has to go looking for your ivars, it has to do a bunch of wading through the Obj-C runtime that isn't necessary if you provide accessor methods.

But the same more or less holds for method lookups, doesn't it?

Not really.

When you send a message for the first time to an instance of a given class, it may have to recurse through the inherited method tables to find the implementation, but it only has to do so once. After that though, it will be in the method cache.

If you let KVC hunt for your ivars, it has to do so every time. I haven't measured it, but since an accessor method can determine the offset to the ivars it affects at compile time, it's going to be a lot faster.

Now, you could argue that writing accessors is a premature optimization, but since there are tools to autmatically generate accessor methods, you might as well use them.

-jcr






John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: KVO and accessors - are they needed
      • From: Steven Kramer <email@hidden>
References: 
 >KVO and accessors - are they needed (From: Bruce Truax <email@hidden>)
 >Re: KVO and accessors - are they needed (From: "John C. Randolph" <email@hidden>)
 >Re: KVO and accessors - are they needed (From: Steven Kramer <email@hidden>)

  • Prev by Date: Re: Tall NSTableView Column Headers
  • Next by Date: Layouting NSTableView Headers
  • Previous by thread: Re: KVO and accessors - are they needed
  • Next by thread: Re: KVO and accessors - are they needed
  • Index(es):
    • Date
    • Thread