Man, our documentation sucks. Here's what it says for LstSetListChoices:
-----
LstSetListChoices
Purpose: Set the items of a list to the array of text strings passed to
this function. This function doesn't affect the display of the list. If the
list is visible, erases the old list items.
-----
I wish it would make up it's mind: does it affect the display or doesn't
it?
Anyway, another area where the docs fall down is that it doesn't mention
that the function results in the list object merely copying the pointer you
pass in. It does *not* copy the strings themselves. That is, you should
*not* free up the memory afterwards.
-- Keith Rollin
Aaron Ardiri <[EMAIL PROTECTED]> on 04/28/99 01:48:08 AM
Please respond to [EMAIL PROTECTED]
Sent by: Aaron Ardiri <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (Keith Rollin/HQ/3Com)
Subject: Dynamic Memory?
hej!
got to the upper limits of size :)) time to be more dynamic..
this is a normal section of standard C code for allocating
a 10x10 array of characters.
---
{
char **myStrings;
int i, count;
// allocate the memory
count = 10;
myStrings = (char **)malloc(count * sizeof(char *));
for (i=0; i<count; i++) {
myStrings[i] = (char *)malloc(10 * sizeof(char));
sprintf(myStrings[i], "%d", count);
}
// do something
...
// free the memory
for (i=0; i<count; i++) {
free(myStrings[i]);
}
free(myStrings);
}
---
a direct port to the palmOS i thought would be like
this:
---
{
CharPtr *myStrings;
int i, count;
// allocate the memory
count = 10;
myStrings = (CharPtr *)MemPtrNew(count * sizeof(CharPtr));
for (i=0; i<count; i++) {
myStrings[i] = (char *)MemPtrNew(10 * sizeof(Char));
StrIToA(myStrings[i], count);
}
// do something (like set the values in a pull down list)
LstSetListChoices(listP, myStrings, count);
// free the memory
for (i=0; i<count; i++) {
MemPtrFree(myStrings[i]);
}
MemPtrFree(myStrings);
}
---
but this gives me unallocated memory errors..
any pointers? should i be allocating memory to
handles and then lock those handles to pointer
references?
the API says the following for MemPtrNew:
---
Allocate a new nonmovable chunk in the dynamic heap.
---
does my code "move" the chunk of memory? :)
cheers.
az.
--
Aaron Ardiri
Lecturer http://www.hig.se/~ardiri/
University-College i G?vle mailto:[EMAIL PROTECTED]
SE 801 76 G?vle SWEDEN
Tel: +46 26 64 87 38 Fax: +46 26 64 87 88
Mob: +46 70 352 8192 A/H: +46 26 10 16 11