Notifications
Notifications
- Subject: Notifications
- From: Simon Stapleton <email@hidden>
- Date: Tue, 28 Aug 2001 11:47:32 +0100 (BST)
Hi there.
As notifications have just recently been mentioned as a major source
of app slowdowns, and I've just been bitten by exactly that problem,
I was wondering if anyone has any ideas on solutions.
My situation is this:
I'm writing a powerkite design application, which has a layered
architecture model - A Kite has many component parts, each of which
has consists of many curves, each of which consist of many points,
etc etc.
For the view classes to work properly, I have to have notification
hookups, and thus I have a base class which defines some convenience
methods as follows.
// Send a given notification
- (void) notify: (NSString *)notification;
// hookup all relevant notifications, should be overridden
// in derived classes
- (void) hookupNotifications;
// remove self as an observer
- (void) unhookNotifications;
This all works wonderfully, all I have to do is hook up the
notifications at the relevant points and I can move a point in one
editor window and have the area of the kite change dynamically in a
textbox in another.
Except. If I change a curve in a major way (i.e. anything that
involves changing all points in a curve at once) I flood the
notification mechanism, and the app freezes while it gets everything
over and done with.
What happens is that every point sends a pointHasChangedNotification,
and for each of these, every interested curve sends a
curveHasChangedNotification, and so on, up the chain. As every curve
could have upwards of 200 points, things can get rather gnarly, as
you can imagine.
I've got round this to some extent by adding the following method
- (void) setSendsNotifications: (BOOL) yesNo;
to the base class and checking the state of this in the notify:
method, and wrapping any 'hairy' processing with a
setSendsNotifications:NO / setSendsNotifications:YES pair, followed
by manually notifying the change
But I still get bitten if someone were, for example, to select all
points in a curve, and drag them dynamically.
Has anyone got any ideas as to how to get round this or reduce the
impact?
I've also got the problem where I have to dynamically regenerate
curves in response to bezier control points moving, but that's a
whole other issue.
Simon
--
If the answer isn't obvious, the question is a distraction. Go find
an
easier question.