Re: +poseAsClass and instance variables
Re: +poseAsClass and instance variables
- Subject: Re: +poseAsClass and instance variables
- From: email@hidden
- Date: Fri, 22 Feb 2002 13:05:42 -0800
Is there anyway around the limitation that classes can't have instance
variables when posing as another class? For my purposes, categories
aren't suitable since I need to ensure that certain methods are
overridden.
You can override methods in categories, just not easily use the
original implementation. But on the over side, you cannot add instance
variables in categories either.
One solution is to store your additional variables in a (static)
NSDictionary, using the instance pointer as the key.
Thanks... Although I'm still looking for a technique with very little
overhead.
Explanation:
I'm using posesAsClass to replace normal NSWindows with ones that are
visual quite different. Most of the instance variables will be used
while drawing during live window resizing. Hence, optimization is sorely
needed. Dictionary lookup is nicely optimized but its still a noticeable
hit when compared to merely accessing an object's value. (right?)
It is slower than a direct ivar access, yes. Nevertheless, the
overhead should be utterly negligible compared to the overhead of
actually redrawing the window at the new size. I wouldn't worry about
this at all. If you *did* find that the dictionary access was slowing
you down, using Sampler or something, then you could try to optimize the
dictionary lookup in various ways. But from your description of what
you're doing, it won't be a problem.
Is there a reason you have to use posing rather than just using a
subclass of NSWindow, by the way? Using posing is almost always the
wrong solution for a given problem, although certainly there are
exceptions. Even if the system is creating the windows for you and you
have no control over the class (and I don't know what part of Cocoa
would be doing that), you might still be able to do what you want by
tweaking the isa pointers of those windows, which is much less invasive
and dangerous than posing...
Ben Haller
Stick Software
_______________________________________________
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.