Re: +poseAsClass and instance variables
Re: +poseAsClass and instance variables
- Subject: Re: +poseAsClass and instance variables
- From: Dennis De Mars <email@hidden>
- Date: Sat, 23 Feb 2002 13:08:52 -0800
If you have a bunch of ivars, wouldn't you just define a struct with all
the extra ivars, then malloc an instance of that and stick a pointer to
that into the static dictionary? You would just do a lookup to get that
pointer at the beginning of each method, so the overhead is one static
dictionary lookup per method invocation. Would that be too much?
- Dennis D.
On Friday, February 22, 2002, at 10:29 PM, Darrin Filer wrote:
I'm actually having a class pose as NSThemeFrame. Subclassing an
NSWindow isn't terribly effective. NSBorderlessWindows don't have have
hardware accelerated window dragging. Nor have I found a way to access
HW accelerated dragging from anywhere but the title bar. Thus, I had to
dip into the private APIs (with significant assistance from a helpful
Swede.)
Is there an easier way to draw into a window's title bar? While I'm at
it, I draw quite a bit of stuff so its necessary to access a static
dictionary quite frequently. The other option is to load the values at
the start of each instance method.
darrin filer
On Friday, February 22, 2002, at 04:05 PM, email@hidden wrote:
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.
_______________________________________________
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.
_______________________________________________
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.