>> Globals are only valid for a UI application running on a
>> sysAppNormalLaunch (and a few other launch codes which are basically
>> the same as a normalLaunch).
>
>Yes, a Desk Accessory is an application that runs as a nested app. Why
>can't it
>have global variables?

There are many cases where a launch code will be sent to applications.  It
takes time to set up the globals for an app, and the app might have lots of
them which would obviously consume a bunch of memory.  Therefore, the
startup code of an app only will allocate memory for globals when it is
"really" starting up, as opposed to being called for a quick little
notification or to ask it to perform a "Find" or whatever.

So it is sort of convention, sort of an OS requirement, sort of an
optimization.  A more full explanation of why and how would take a lot of
typing, and understanding of how compilers work and how they allocate
globals and statics and such... if you're not wanting to get at that level
of detail, just take it as given that you don't have globals available to
you except in a normalLaunch. :-)

(If you want to write some tweaky code, you could save off the old A5
register, which is used to point to the currently running app's globals,
allocate memory for your globals, set A5 to it, use the globals, and then
carefully reverse the process when quitting or when calling into other
programs or OS APIs... or you could do something similar with A4...)

-David Fedor
Palm Developer Support


Reply via email to