> From: Jeremy Nuss
>
> 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);
>

Well, not really.  What is n in memptr[n]?  What about each memptr[x], where
1 <= x <= items?  For a completely useless example that will "work" (though
I didn't bother to test it):

  Char ** memptr;
  UInt16 i, items = 10; // for example

  // allocate an array of pointers
  memptr = (Char**)MemPtrNew(sizeof(Char*) * items);
  for(i = 0; i < items; i++)
    memptr[i] = (Char *)MemPtrNew(StrLen("Some String") + 1);

  // free the array of pointers
  for(i = 0; i < items; i++)
    MemPtrFree(memptr[i]);
  MemPtrFree(memptr);

I moved the declaration of i to the top because I'm using C, not C++.  That
change shouldn't have any impact on the code under C++.


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to