Mark Chauvin wrote:
How do you reduce the size of the heap being used by
an app? I've already got cw set to optimize smallest
code. Is there a compiler setting or directive for
heap usage?
Code size isn't related to dynamic heap in a Palm OS app.
All your code is stored in resources, and they reside in
the storage heap. For the purposes of your application,
the code is read-only, and it does not need to be copied
from the storage heap to be executed, because while a
record in the storage heap is locked, it is addressable
just like other memory. So, you can make your code
small or large and it will make no different in the
dynamic heap usage.
Dynamic heap is what is used when you do a malloc(),
a C++ "new", a MemPtrNew(), a MemHandleNew(), or any
function that calls any of these[1].
Also, if I understand correctly, the runtime code that
CodeWarrior produces (or the Palm OS application loader?
probably the former) puts all your global variables in
the dynamic heap at the time the app is launched. This
would also apply to static local variables, since although
they don't exist in the global namespace, they use the
same kind of storage.
Maybe the best thing to do with regards to dynamic heap is
first figure out how much of it your app is using. You
can do that by running on a newer device and calling
MemHeapFreeBytes() on the dynamic heap[2] periodically,
perhaps logging the results to a data file or something.
As far as I know, there isn't a tool that automatically
traces heap usage for you, although that would be handy
if it did exist. Anyway, the point is that if you know
how much heap you're using, you can figure out whether
having a small heap is really a problem or not.
- Logan
[1] For example, BmpCreate() creates its bitmap in
the dynamic heap.
[2] You can call MemHeapDynamic() on heap IDs from
0 to MemNumHeaps()-1 in order to figure out the
ID of the dynamic heap. On newer devices there
should be just one dynamic heap.
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/