Brandon Wallace wrote in message <8678@palm-dev-forum>...
>
>> >/***********************************************************************
>> > *
>> > * FUNCTION: UnpackInfo()
>> > *
>> > * DESCRIPTION: This routine unpacks a packed Info structure
>> > *
>> > * PARAMETERS: info - Pointer to a Info structure
>> > * packedInfo - Pointer to a packed Info structure
>> > *
>> > * RETURNED: void
>> > *
>> >
***********************************************************************/
>> >void UnpackInfo(tblInfoPtr info, const tblPackedInfoPtr packedInfo)
>> >{
>> > const char *s = packedInfo->Strings;
>> > info->UnitType = packedInfo->UnitType;
>> > info->Beginning = packedInfo->Beginning;
>> > info->Ending = packedInfo->Ending;
>> > info->Number = packedInfo->Number;
>> > info->TNumber = s;
>>
>> Bad boy! You are having the char * field TNumber point
>> directly into the packedInfo memory. Assuming that packedInfo
>> is a temporary thing used only while unpacking you will end
>> up with nothing very shortly. What you need to do is to -copy-
>> that information. Try this:
>>
>> info->TNumber = MemPtrNew(StrLen(s)+1);
>> StrCopy(info->TNumber, s);
>>
>> ... same goes for all of the following strings.
>
>
>If he is following the O'Reilly book example, which I think he is,
>then this is how the book does it. The book does warn that you
>must keep packedInfo around or else the unpackedInfo becomes
>invalid. Saves on memory and clock cycles if you can keep that
>straight.
>
Well, I did say "assuming that packedInfo is temporary". Yes,
if you keep it around, your pointer will still be good. Otoh, if you
ever plan on changing the value of that string you will still be
limited to the length that it occupies in packedInfo. If you allocate
new memory and copy, then later if you need to change it to a
longer string you can realloc to a larger size.
--
-Richard M. Hartman
[EMAIL PROTECTED]
186,000 mi/sec: not just a good idea, it's the LAW!
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html