If you plan to keep the data available to your app for awhile, you may want
to use movable Handles instead of fixed pointers.
Handle hAuthorList;
Char *pAuthorList;
hAuthorList = MemHandleNew (Sizeof(Char) * NumAuthors *
AuthorNameMaxLength);
...// Program code
pAuthorList = (Char *) MemHandleLock(hAuthorList);
// Use your pAuthorList array, load the array, modify an entry, etc...
MemHandleUnlock (hAuthorList); // Unlock the handle when done
// relock/unlock as often as you need to but don't keep it locked any longer
than you have to.
...// More program code
// Deallocate hAuthorList when done
Handles can be moved around in memory (when not locked) while pointers
remain locked and immobile. Using a pointer to store your array may cause
memory fragmentation if you plan to keep the pointer around for a length of
time. If you plan to only use your AuthorList for a short period, then
pointers will work fine.
----- Original Message -----
From: "Craig Austin" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Monday, January 22, 2001 11:00 AM
Subject: RE: Dynamic Size of array
> Just create a global character pointer.
>
> char * globalList;
>
> then in your function allocate new memory.
>
> if (globalList != NULL)
> MemPtrFree(globalList);
> globalList = MemPtrNew(DmRecordsInCategory(dbAuthors, dmAllCategories));
>
> LstSetListChoices(ListPtr, globalList, iNumAuthors);
>
>
> But don't forget to do the error checking, and freeing up the memory.
>
> Craig
>
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Phillip
> Koebbe
> Sent: Monday, January 22, 2001 8:49 AM
> To: Palm Developer Forum
> Subject: Dynamic Size of array
>
>
> Is it possible to create an array that on each execution of the method it
> is potentially a different size? For example, let's say I've got a
> database of authors. On my form, I want to have a list box to display all
> of the authors. To use LstSetListChoices, I have to pass it an array. I
> would rather not have a constant define the size of the array because then
> I would have to tell the user "There is a limit of x authors." I want it
> to be unlimited. Here's what I want to do (conceptually):
>
> static void LoadAuthors(void)
> {
> ...
>
> // query database to see how many authors there are
> iNumAuthors = DmRecordsInCategory(dbAuthors, dmAllCategories);
>
> // instantiate the array
> Char* AuthorList[iNumAuthors - 1];
>
> ...
>
> LstSetListChoices(ListPtr, AuthorList, iNumAuthors);
> }
>
> But that doesn't work. Is there a way to accomplish this?
>
> Thanks,
> Phillip
>
>
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/tech/support/forums/
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/