I want to Call MemHeapCompact after call MemHeapID right now. Do MemHeapCompact spend too much time?
I'm glad to help you, but I do suggest you look up the API documentation. The questions you asked in this thread are basically all answered there.
Anyway, back to your question. You would use MemHeapCompact after calling MemHeapFreeBytes and finding out there's not enough free space available:
UInt16 heapID; UInt32 free, max; MemPtr p = NULL;
MemHeapFreeBytes(heapID, &free, &max);
if (max < 60 * 1024) {
// Try compacting the heap to see if this frees up more space.
MemHeapCompact(heapID);
MemHeapFreeBytes(heapID, &free, &max);
}if (max >= 60 * 1024) {
p = MemPtrNew(60 * 1024);
} else {
// Signal allocation failure.
}Anyway, there's more information in the API docs.
Regards -Laurens
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
