I think the worst risk in using an unlocked handle is that you get a bug
that is very difficult to reproduce. The program may simply crash for no
apparent reason.
Cleanup is always a burden in Palm OS programs, but there are some
techniques that can ease this. When I had a situation similar to yours I set
a maximum length of a string in a resource and wrote a utility function like
this one:
char *GetResourceString( UInt16 id ) {
static char string[256];
char *temp;
MemHandle h;
UInt16 i;
h = DmGetResource(...);
if ( !h ) return NULL;
temp = MemHandleLock( h );
i = StrLen( temp );
if ( 255 < i ) i = 255;
MemMove( string, temp, i+1 );
if ( 255 == i ) string[256] = '\0'; // Make sure the string is
null-terminated
MemHandleUnlock( h );
DmReleaseResource( h );
return string;
}
This returns a string that is valid until the next time someone calls
GetResourceString(). Any string longer than 255 characters is truncated. No
cleanup call is needed.
I just threw this function together, so I don't guarantee that it's
bug-free. :)
Bob Whiteman
Senior Software Engineer
Pico Communications
"Max Bian" <[EMAIL PROTECTED]> wrote in message news:75519@palm-dev-forum...
>
> Thanks for the explaination. I would be using it immediately after that.
As
> Steve said in another reply, it can still be risky.
>
> I was thinking about a cheap way to do the thing using a function without
> having lots of UnLock and Release floating around.
>
> Well, I think it is better to be safe than sorry.
>
> Thanks.
>
> Max
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/