bartop

palmoswerks ARCHIVE
Palm OS programming tips from a (former) CodeWarrior insider

header

Navigation

Search
Home
About
Stories
Stuff I Like
Articles
PilRC
CodeWarrior
palmos.techwood.org
DevTools List
Palm OS Dev FAQ

What Drives Exception Table Size

I was talking to some developers on a mailing list about the Bear River's Palm Application Framework, and a few of them were having problems with their local data getting too large, in part due to the size of the exception handling table. Exceptions in CodeWarrior come with a bit of extra overhead; CW uses a technique called "zero-overhead" exceptions. That isn't entirely accurate; the zero part refers to extra code that has to be executed when no exceptions are thrown. Rather than insert code to register objects, the compiler builds a static table that maps locations in the code to sets of objects that should be destroyed.

In my talk at PalmSource 2002, I commented that using "throw ()" on methods and functions to tell the compiler that something can't thrown an exception was a good technique to reduce the size of these tables. Well, it is, but sometimes it isn't.

Exception table size is finicky, because its is proportional to the number of different "destructor" states that code can have; the table grows whenever the set of objects in a function that would have to be destroyed when an exception is thrown changes.

The theory behind throw() affecting the table size is that if you have a function that looks like:

void foo()
{
    obj_with_destructor bar;


    FrmLoadForm(frm);
    StrPrintF(str, "%s", "test");
    ....
}

A minimal exception table would have to be generated for this function, since no exceptions can be thrown during the lifetime of obj. On the other hand, if FrmLoadForm and StrPrintF were not tagged as "throw ()", then an exception could be thrown from the functions, and the table entries to destroy the object bar would be needed.

For throw() to be effective, it needs to be consistently used, kinda like the const modifier. In code you write yourself, throw() can also lead to some bloat, because if a function declared as throw() calls a function that can throw exceptions without having the appropriate try/catch, then the compiler inserts its own "catch(...)" that calls the runtime libraries terminate() routine to ensure that no exception will leave the function.

Exception managment is tricky... I hope this text helps you find ways to reduce table sizes, and make better use of C++ on the Palm OS platform.

brought to you by weblogger.com


Send feedback to combee@techwood.org
Copyright © 2004 Benjamin L. Combee
Palm OS is a registered trademark of PalmSource, Inc.
Metrowerks and CodeWarrior are registered trademarks of Metrowerks Inc.

The views expressed on this website/weblog are those of mine alone and do not necessarily reflect the views of PalmSource or Metrowerks.

This is a Manila Site

qwertYAK / frobnovich