I use MemHeapCompact(0) but it is not working! So I have a lot of free memory but can not use it because of fragmentation (as I suppose).
I think you're overly optimistic about what MemHeapCompact can do. It can't magically cure all fragmentation, though it can help sometimes. Depends on how things have been allocating memory.

If a chunk of memory was allocated as a handle with MemHandleNew, and it isn't locked, then MemHeapCompact can move it around to minimize fragmentation. But if something has allocated a non-moveable chunk by using MemPtrNew, then the OS can't move that bit of memory, so MemHeapCompact properly does nothing with it. It can thus cause fragmentation, depending on when and where it was allocated.

That's the difference between MemHandleNew and MemPtrNew... and why you want to use handles whenever possible, particularly for longterm allocations.

You might consider allocating large hunks of memory in the storage heap. Few things are ever locked in the storage heap, and it is much bigger anyway, so you've got a better chance of the system being able to produce a big contiguous chunk there.

-David Fedor
PalmSource, Inc.

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

Reply via email to