• 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: I think I get most of the memory stuff but...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I think I get most of the memory stuff but...


  • Subject: Re: I think I get most of the memory stuff but...
  • From: Marcel Weiher <email@hidden>
  • Date: Mon, 5 May 2003 15:11:49 +0200

If profiling showed the setter method to be a bottleneck, I'd compare the pointers and avoid the autorelease/retain cycle entirely when possible. A pointer comparison is cheap, and it remains clear at first glance that the case where aString == clientCode is handled differently.

That would optimize a rare case, the common case would still be slow.

Perhaps it's just my background showing. I've done a lot of Perl programming over the past few years, and I've been burned far too many times by idiomatic code that was slick, efficient, and a royal pain to decipher. I've learned to favor clarity on the first pass, profile the app, and then optimize away the clarity only where necessary.

While I agree with this sentiment, the problem is that accessors tend to not be bottlenecks in themselves, but rather a performance issue that is widespread. And modifying all the accessors in a program can be a lot of pain.

Anyway, I think (know) that we can do better, because this code is so idiomatic that it shouldn't concern us *at all*. Just use accessor-macros:

idAccessor( clientCode, setClientCode )

generates a pair of accessor methods for the 'clientCode' instance variable. I usually get all my plain accessors out of the way at the start of my .m file, and then have room both in the code and in my head for the actual meat. If it turns out I need to do more processing for the set-accessor, I usually just rename the boiler-plate one:

idAccessor( clientCode, _setClientCode )

and then code the extra:

-(void)setClientCode:newCode
{
[self _setClientCode:newCoder];
//--- now notify everyobdy that the client code changed...
}

Since it has to be coded only once, and is not usually visible, it can be done right and optimized.

Cheers,

Marcel

--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
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: I think I get most of the memory stuff but... (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Hide/Show an NSView???
  • Next by Date: problem with NSMatrix AND Contextual Menus
  • Previous by thread: Re: I think I get most of the memory stuff but...
  • Next by thread: Re: I think I get most of the memory stuff but...
  • Index(es):
    • Date
    • Thread