Re: Recuperating after NS_HANDLER
Re: Recuperating after NS_HANDLER
- Subject: Re: Recuperating after NS_HANDLER
- From: Shaun Wexler <email@hidden>
- Date: Sun, 16 May 2004 13:52:47 -0700
On May 16, 2004, at 7:41 AM, j o a r wrote:
It smells like a premature optimization to me...
j o a r
Yeah, that's what SHE said. It all adds up; not everyone has to worry
about things like this, but if they're writing a real-time
application... ;)
On 2004-05-16, at 15.45, Shaun Wexler wrote:
This is better:
do {
NS_DURING
while(someStuff) {
something that could throw an exception;
}
NS_HANDLER
handle it;
NS_ENDHANDLER
} while (someStuff);
Entering and exiting exception handlers carries a lot of overhead...
;)
Even if it's just a few loop iterations, each time you enter an
exception block, it has to retrieve the current pthread to get the top
handler from the thread-specific data, then walk the list of handlers.
Then it adds this block to the linked list of exception blocks, and
changes the setjmp. That's expensive in many ways, especially if
objects in the loop throw often. The above example could be better
illustrated:
BOOL continueLoop = YES;
do {
NS_DURING
while(someStuff) {
something that could throw an exception;
}
continueLoop = NO;
NS_HANDLER
handle it;
if fatal err, set continueLoop = NO;
NS_ENDHANDLER
} while (continueLoop);
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
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.