Dear Rhys,
For MemPtrResize to enlarge the chunk (as in your case from 128 to 140),
there must be memory available immediately following the chunk. If it isn't
(as will often be the case), it will fail.
You have the right idea with doing a MemPtrUnlock. This unlocks the chunk so
it can be moved to a new location when it is resized. But, as soon as the
chunk is unlocked, the pointer becomes invalid! That is, Palm OS can move
any memory chunk which is unlocked. When you resize it, Palm OS will often
move it.
In order to reliably enlarge a chunk of memory, you must use
MemHandleResize, the chunk must be unlocked, and the chunk must be movable
(as such a chunk is when created with MemHandleNew). It is going to be
difficult to avoid using handles, a central aspect of memory management in
Palm OS.
This is the sequence you need to use:
1. MemHandleNew
2. MemHandleLock
3. Work with locked chunk until you determine it needs to be enlarged.
4. MemHandleUnlock
5. MemHandleResize to enlarge it
6. MemHandleLock
7. Work with enlarged locked chunk.
8. MemHandleUnlock
9. MemHandleFree
Good luck!
-----Steve Jackson
"Rhys Arkins" <[EMAIL PROTECTED]> wrote in message
news:12776@palm-dev-forum...
>
> Is there anything tricky which must be done to a pointer before it can be
> resized? I have a problem in my code which involves a MemPtrResize call
> failing due to the memErrChunkLocked error. Just to test this I even
created
> simplified code like:
>
> uchar *buf = MemPtrNew(128);
> if (MemPtrResize(buf, 140) == memErrorChunkLocked)
> foobar();
>
> and even this appears to fail due to the chunk locked error. I tried
putting
> a MemPtrUnlock(buf) in before the resize, but it still appears to fail.
Can
> anyone enlighten me on the correct procedure for allocating and resizing
> pointers? (I'm aware of MemHandles but in this instance would much prefer
to
> use MemPtrs).
>
> thanks for any assistance.
>
> Rhys.
>
>
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/