Jim, I'd do exactly what you are doing. You can free the handle outside of the function--no problems there. It's really a matter of choice, but I prefer not to use globals if I can get around it. You may want to use MemPtrNew instead of MemHandleNew, it'll save a few lines of code and if you're only allocating 80 bytes there's not much to worry about, but again it's really up to you.
Cheers, Tim "JAMES S HAINES" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I've created a subroutine to pad a string on the left with blanks. The > question is- since the handle padH is created in the function and passed > back to the calling routine, how do I free it? Is it better to have it as > a global variable or do I create it in the calling function and free it > there also? How do others handle this situation. > Thanks in advance. > Jim Haines > > MemHandle strPadLeft(char *str, UInt16 maxLen) > { > char *padStr; > UInt16 padLen,i; > MemHandle padH; > padH=MemHandleNew(80); > padStr=MemHandleLock(padH); > padLen=maxLen-StrLen(str); > StrCopy(padStr," "); > for(i=1;i<(2*padLen);i++) > StrCat(padStr," "); > StrCat(padStr,str); > MemHandleUnlock(padH); > return padH; > } > Jim Haines -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
