Hi Rhys,
You can use MemPtrRecoverHandle using a pointer obtained by calling
MemPtrNew.
Yes. You can do this (if you must):
1. MemPtrNew
2. Use the chunk.
3. MemPtrRecoverHandle
4. MemHandleUnlock
5. MemHandleResize
6. MemHandleLock
7. Use the enlarged chunk.
8. MemHandleUnlock (or MemPtrUnlock)
You can rely on being able to increase the size of a chunk created with
MemPtrNew. You just cannot rely on being able to increase the size of a
chunk when it is locked. And, when you resize the chunk using
MemHandleResize, the pointer obtained when you re-lock it with MemHandleLock
is likely to be different than the prior one.
You could logically replace an malloc with:
1. MemHandleNew
2. MemHandleLock
-or-
1. MemPtrNew
You could logically replace a free with:
1. MemHandleUnlock
2. MemHandleFree
-or-
1. MemPtrFree
You can resize a chunk with:
1. MemHandleUnlock
2. MemHandleResize
3. MemHandleLock
Memory management is covered well in Chapter 6, Memory, in the Palm OS
Programmer's Companion. This document is available in Adobe Acrobat form and
is part of the SDK.
Good luck!
-----Steve Jackson
"Rhys Arkins" <[EMAIL PROTECTED]> wrote in message
news:12785@palm-dev-forum...
>
>
> "Steve Jackson" <[EMAIL PROTECTED]> wrote in message
> news:12777@palm-dev-forum...
> [snip]
> >
> > 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
>
> Thanks for the reply, Steve.
>
> I have another couple of questions for the gurus:
>
> I know it's possible to recover the handle from a MemPtr, but is this only
> possible to do if the MemPtr was obtained from locking a MemHandle?
> i.e. can I go MemPtrNew, then if I need to grow it do MemPtrRecoverHandle,
> MemHandleUnlock, MemHandleResize, and then MemHandleLock again to get a
> pointer to the increased buffer?
> (I'm guessing not, but it's worth a shot)
>
> Secondly, given that you should never rely on being able to increase the
> size of buffers obtained from MemPtrNew, how do you recommend going about
> programming things like variable length arrays and structs. For instance,
in
> my code I have a variable length array of structs which contain variable
> length strings, which means I need 3 lots of malloc'ing if it was normal C
> to do (once for the array, again for each struct, and the third time for
> each string). If I am to rewrite this using Handles it looks like a huge
> hassle. Any suggestions or advice?
>
> thanks again,
> Rhys.
>
>
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/