John, the important thing to remember it that when you define a structure like...
ComDB abc;
...it sets aside enough STACK space to hold the whole structure when your program tries to run. In fact, if you declare other instances of this structure in a whole bunch of places then the stack usage will grow and grow.
The problem is that the stack size is dependant on the device, and it is a small fraction of the total available memory.


If, instead, you do what Jan suggsests, and only declare a pointer to the structure (*abc), then the stack only holds the pointer, which is just a 4-byte address. Then, at runtime, you have to dynamically allocate enough memory to hold the structure. This is the MemPtrNew command. This dynamic allocation uses the data heap, and it is usually capable of holding much larger structures, depending on how much stuff is already loaded on the device.

Does that make sense?  Bob.

Jan Slodicka wrote:

1. How can I decrease the stack usage for this function. How would I use the
MemPtrNew to allocate it in the heap instead of the stack?

Instead of
   ComDB abc ;
use
   ComDB *abc = (ComDB*)MemPtrNew( sizeof(ComDB) ) ;
   ...
   MemPtrFree( abc ) ;

2.
yes - as above






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

Reply via email to