Isn't the difference here down to the way PalmOS handles the memory chunks
that are generated by the different calls?
As mentioned, MemPtrNew generates an unmovable chunk of memory - and should
be freed off with MemPtrFree.
MemHandleNew generates a movable chunk of memory. This means that subsequent
calls to MemHandleLock may well return different pointer values. Of course,
whilst locked that chunk will not move so you can call MemPtrFree on it -
but if you unlock that memory then you must use MemHandleFree or you may end
up trying to free off something else!

Laurence.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Ben
Combee
Sent: 27 January 2002 05:28
To: Palm Developer Forum
Subject: Re: Freeing Memory - Approach


> Personally, I felt that "MemPtrFree" is missing something. Although it
did
> release the memory back to the OS, but it seems to be still holding
some
> information of that memory block.

You are too paranoid about this.

All memory in the dynamic heap is stored as chunks.  A chunk has a lock
count.  MemPtrNew gives you a chunk with a lock count of 15, which is a
signal to the OS that this chunk cannot be moved.  MemHandleNew gives
you a chunk with a lock count of 0, and it also allocates a handle in
the handle list.

When you do a MemPtrFree, you actually are calling MemChunkFree.  This
routine looks in the chunk header and knows if there is an attached
handle, so it will always free the correct amount of memory.  When you
call MemHandleFree, it just turns the handle into a chunk pointer, then
calls MemChunkFree.



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


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

Reply via email to