• 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: How Can I Notify DrawRect Method?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How Can I Notify DrawRect Method?


  • Subject: Re: How Can I Notify DrawRect Method?
  • From: Ricky Sharp <email@hidden>
  • Date: Tue, 9 Dec 2008 19:09:49 -0600


On Dec 9, 2008, at 5:31 PM, I. Savant wrote:


Even if it were slower, contorting the code like this without
having profiled the code and demonstrated that this is in fact a
significant slowdown is bad practice.

I disagree. Certainly it's "profile first", but to have a view that reads a simple property from user defaults every time it draws requires more overhead than using an instance variable. Especially when you're using an NSColor object which must be properly archived and unarchived.


Imagine adding complexity to this view and using multiple values like this per draw cycle, and having to draw a whole bunch of stuff. Directly reading colors from user defaults is suddenly a whole lot more expensive.

It doesn't matter much for the simple case the OP presented, but it certainly does for a custom view that does heavy drawing, especially if it's involved in an animation.


Completely agree. For all my custom views, I always create and cache various drawing objects. These are often build-once objects. I usually build them lazily as well.

e.g. I have an attribute named 'needsCreateColors'. When drawRect is called, it checks that flag and calls 'createColors' if needed.

In some cases, other attributes, when set, will 'dirty' that flag followed by a setNeedsDisplay. Colors will then be re-fetched/created and then reused until the next change comes along.

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: How Can I Notify DrawRect Method?
      • From: "I. Savant" <email@hidden>
References: 
 >How Can I Notify DrawRect Method? (From: "Chunk 1978" <email@hidden>)
 >Re: How Can I Notify DrawRect Method? (From: "I. Savant" <email@hidden>)
 >Re: How Can I Notify DrawRect Method? (From: "Michael Ash" <email@hidden>)
 >Re: How Can I Notify DrawRect Method? (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: performance problem with IORegistryEntryCreateCFProperties
  • Next by Date: Custom NSTableView cells
  • Previous by thread: Re: How Can I Notify DrawRect Method?
  • Next by thread: Re: How Can I Notify DrawRect Method?
  • Index(es):
    • Date
    • Thread