> I have seen a lot of warnings about conserving dynamic heap
> and stack memory, etc.  I have seen warnings about keeping
> global variables to a minimum but I have also seen warnings about too
> many local variables.  But what are these limits.
>
> How much RAM is available for local variables?
> How much is available for global variables?
> How large is the stack?
>
> "Conserve" is kind of a vague term.  I have an app that has
> over 3k of global variables (mostly arrays).  Is that a lot
> in terms of the "conserve memory" warnings?
>
> I have the API docs and have Palm Programming but they just say
> conserve it because RAM is limited for dynamic memory, etc.  Where
> the actual limits discussed?
>
    As somebody already pointed out, the limits are documented in:

http://www.palm.com/devzone/docs/palmos/Memory.html#610717

but in general, conserve means just that.  Sometimes it means using an
algorithm that takes longer but uses less storage.  It could mean
calculating some values on the fly instead of storing them, or re-thinking
your data structures so they occupy less memory.  If an array has a high
theoretical upper limit but in practice is rarely that large, you should
think about allocating it dynamically or having it grow as needed.
Sometimes even the decision between global variables, local variables, and
dynamically allocated memory can be significant as well, because of
differences in the way each type is allocated.  As I'm sure you know, locals
are on the stack, so a recursive algorithm with a lot of locals can get you
into trouble fast (the stack really isn't very large).  Pay particular
attention if you're using C++, because passing large structures or classes
by value can blow your stack in no time.  If I recall correctly, globals end
up in a single memory chunk allocated on the heap, but I may be mistaken.
You also have to keep in mind that some devices (older ones, usually) have a
harder time allocating large memory chunks because of the way the heaps are
configured and compacted - an app that runs fine on a Palm V may fail
randomly on a Palm Pro because it can't allocate a large enough block of
contiguous memory...



--
Dan Rowley
Innovative Computer Solutions
Developers of fine software for Newton, Windows CE, Palm Computing Platform,
Windows, and MacOS

Reply via email to