At 14:24 2002-12-2 +0100, you wrote:
Ok, but where can i found infos about how to correctly code
a multi-segment C++ app. It seems that the place of each parts
in segments a really important for code stability.
It should not be, except in a few circumstances.

First, in a Palm OS program, code and data have separate segments. Even if you have a multi-segment program, there usually is just one data segment that is seen by all the code segments. (The exception is expanded mode apps -- they have two data segments, but I won't go into that here).

When Palm OS starts an application, it loads up the 'code' 0 segment to get information about how much data space is needed by the program, and then is loads the 'code' 1 segment and jumps to the start of this code to get it going.

Usually, this startup code is provided by a runtime library. CodeWarrior ships with two runtimes: there's a very basic StartupCode.lib that is written by PalmSource and only provides support for single-segment apps, and there are the more complex "PalmOS_Runtime" libraries that were created by Metrowerks and support C++ and multiple-segment applications.

Tip: make sure you are using the correct runtime library for your project type. If you're using C++ or doing multi-segement apps, be sure to switch your project to the PalmOS_Runtime_2i_A5.lib file. You would use one of the other lib files if you were doing an expanded mode program or if you used 4-byte integers, but those are the exceptions, not the rule.

OK, so assuming your runtime is correct, you should be aware that the runtime library does a few things on startup:

0) The OS has already setup the data space, copied data to it from the 'data' 0 resource, and done the initial relocations.

1) If you're on a global launch code, lock the additional code segments in memory. For each code segment, perform additional relocations specified at the end of the code.

2) Setup the jumptable that allows different code segments to call each other.

3) Call the initialization code setup by the linker to call the constructors for any global objects.

4) Call your PilotMain

5) Call the destructors for global objects.

6) Unlock the additional code segments locked by the initial runtime code.

Nothing here should prevent your data from working no matter where it is. I'm hoping this explanation will help you better understand what's going on in a multisegment app.



--
Ben Combee <[EMAIL PROTECTED]>
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com


--
For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/


Reply via email to