You have a very small stack space for local variables, as low as 2.5K on
some devices.  A single "char buffer[1024]" uses up almost half of the
available space.

While you could declare the buffer as a global, now you have 1K permanently
allocated to a buffer that is only used a brief periods of time.  It would
be much better to dynamically allocate the buffer before you use it, then
free it afterwards, with only the buffer pointer stored on your local stack,
ala

char *buffer;

buffer = MemPtrNew(1024);
if (buffer)
{
    // code that uses buffer
    MemPtrFree(buffer);
}
else
{
    // fail gracefully
}

You may have to write some extra code to deal with the rare situation where
you couldn't allocate the buffer, but a robust program should already have a
good mechanism for dealing with out-of-memory conditions, even if it just
cleaning everything up and aborting back to the launcher.

"Jason Simpkins" <[EMAIL PROTECTED]> wrote in message
news:9475@palm-dev-forum...
>
> I am fighting weird freaky memory problems and it is driving me insane.
> Currently if I have large
> local char buffers in my functions, such as char buffer[1024], I am
getting
> a "....tried to change the PC
> to address 0x3FE0098....address is niether in RAM or ROM....blah blah
> blah....".   If I declare the buffer as a global no more crashes....like
the
> one above.  However, when reading the "companion" documention on the Palm
> web site, it advices, in one sentence to use globals, then four sentences
> later advises against it?!   WTFO?    What is the "offical" "smart" "best"
> way of declaring and using memory?  I mean, I'm trying to use standard K
and
> R techniques here but just ain't working!




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to