• 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: Steven Kramer <email@hidden>
  • Date: Sat, 23 Oct 2004 15:54:50 +0200


Op 22-okt-04 om 21:52 heeft John C. Randolph het volgende geschreven:


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.


Agreed, but even then KVC will have to do some runtime mangling (looking up argument types for type coercion). So it never becomes a truly trivial operation, right? I'm asking because I have a situation with quite some classes that are mostly data containers. Adding getters/setters increased the class and code size considerably and speed is not such an issue here.

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.


Half on-topic: I have an easily customized yet slightly powerful perl script for Xcode to do accessors/init/dealloc/coding implementations. Much better than the Apple supplied shell script. If anyone's reading this and interested, let me know.

Regards

Steven

_______________________________________________
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: Scott Stevenson <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>)
 >Re: KVO and accessors - are they needed (From: "John C. Randolph" <email@hidden>)

  • Prev by Date: Re: performance of adding subviews
  • Next by Date: Binding & Change Count
  • Previous by thread: Re: KVO and accessors - are they needed
  • Next by thread: Re: KVO and accessors - are they needed
  • Index(es):
    • Date
    • Thread