How inefficient is validateMenuItem?
Lon Varscsak
varscsak at smarthealth.com
Fri Jul 11 19:10:35 PDT 2008
I would agree with what most of the others have said as well...with one
exception. I've done this before where you have to lookup a value in a
database (server, not local storage) and while it's very fast, it can make
your menu navigation sluggish. Prefetching and/or caching eliminates those
problems.
But for the average run of the mill validateMenuItem: logic, I wouldn't
worry about it.
Lon
On Fri, Jul 11, 2008 at 5:44 PM, Jim Witte <jswitte at bloomington.in.us>
wrote:
> I'm reading through Hillegass's Cocoa Programming and am up to the bit
> about menu updating using validateMenuItem. It seems that using
> validateMenuItem for something that is not likely to change EVERY single
> time the menu is opened would be rather inefficient as opposed to simply
> pulling the Carbon MenuRef from the NSMenu somehow, and then using a Carbon
> function to disable the item. It might even be inefficient for ANY item, no
> matter how often it's called, and it also (in some circumstances) takes the
> 'menu item disable logic' away from the place where the menu item is
> actually disabled in the code - if that makes any sense (I do something that
> causes the item to have no meaning in one place, but don't tell the system
> to disable it until in the validateMenuItem, which is in a completely
> different place perhaps).
>
> Plus, since the same validateMenuItem routine is called for each menu (and
> possibly more than one menu if you've set it up that way) - if there are
> several items that need to be checked, it's not clear how efficient the
> menu-item check code is going to be (a giganitic switch statment on
> menuItemNumber of whatever.. And if @selector() has to convert the NSString
> *at runtime* to a selector code.. Forget it)
>
> If an individual NSMenuItem could be connected to a specific
> validateMenuItem routine, this might decrease the 'mutliple item switch'
> overhead (although it increases code size, and if routines are found at
> runtime, then..)
>
> What are the general practices for when to use validateMenuItem and when
> to just use the Carbon functions or.. are there other ways to disable
> items?
>
> Thanks,
> Jim Witte
> _______________________________________________
> MacOSX-dev mailing list
> MacOSX-dev at omnigroup.com
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>
More information about the MacOSX-dev
mailing list