No, actually, that code will not work. Two reasons:
* Your loop will hit only the first element. sizeof(memptr) is 4,
and sizeof(char *) is also 4, so the result is 1. You need to replace
that expression with "items".
* The array buffer is mostly uninitialized. The only initialized
element is the nth element. Therefore, in your loop, you're passing
garbage to MemPtrFree.
-- Keith Rollin
-- Palm OS Emulator engineer
At 4:25 PM -0500 7/11/01, Jeremy Nuss wrote:
>Okay thanks everyone, sorry if I'm using this forum inappropriately! I wont
>ask generic C++ questions every again, I promise.
>
>The following code aught to work properly then.
>
>char ** memptr;
>memptr = (char**)MemPtrNew(sizeof(char*) * items);
>memptr[n] = (char *)MemPtrNew(StrLen("Some String") + 1);
>for(UInt i = 0; i < (sizeof(memptr)/sizeof(char *)); i++)
>{
> MemPtrFree(memptr[i]);
>}
>MemPtrFree(memptr);
>
>-----Original Message-----
>From: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED]]On Behalf Of Jeff
>Wheeler
>Sent: Wednesday, July 11, 2001 3:04 PM
>To: Palm Developer Forum
>Subject: Re: Memory Management question
>
>
>> char ** memptr;
>> memptr = (char**)MemPtrNew(sizeof(char*) * items);
>> memptr[n] = (char *)MemPtrNew(StrLen("Some String") + 1);
>> MemPtrFree(memptr);
>>
>> Does this statement code free up all the memory that was allocated for the
>> array of strings?
>
>Yes, it frees the memory allocated for the array of strings, but no, it does
>not free the individual strings pointed to by the elements of this array.
>For every successful MemPtrNew(), you need a MemPtrFree().
>
>Jeff
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/