Thanks David,
I did get a great response from Jason Dawes yesterday.
I'll forward it to you if you like since I don't think
it went to the list.
I spend some time studying the Palm OS docs and O'Reilly
book, and decided that moveable chunks are always better
than standard global variable allocations for larger memory
allocations. So I might as well do this right from beginning.
My applications would either be too computationally intensive
for Palm, or need several large lookup tables. The number
of large (3-4K) lookup tables will increase in future versions
of the app, so I need to find a way to handle them efficiently.
I decided to set up one or two moveable chunks of memory that
are allocated when the application starts. Then, as I
switch between forms, I'll load the lookup tables associated
with that form into the moveable chunks.
>From Jason's comments, I am working today to figure out
how to put these lookup tables into a database. Probably one
chunk per table since they will all be under 4K. The
reason I didn't try this sooner is that somewhere I read
that floating points eat up a lot of space in a database,
and I have a lot of floating point values in my tables.
Now I think I'm going to convert them all to Long integers,
so it probably won't matter.
Paul Fearn
[EMAIL PROTECTED]
-----Original Message-----
From: David A. Smith [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 16, 1999 11:25 AM
To: Paul Fearn
Subject: Re: assigning structure array to moveable chunk
Paul,
I haven't seen any responses your to inquiry yet. I have some comments,
but not a complete solution, sorry. Also, I have a question for you
at the end.
Regarding the first question:
> // what syntax do I use to place this huge structure array
> // into the moveable chunk?
>
> // SomeKindOfPointer = MemHandleLock(lookupTableHandle)
You've already got the answer on this one. The pointer type would be a
pointer to a (single) instance of the structure. At this point,
standard (but not necessarily obvious) C++ pointer arithmetic kicks in.
partinTable* arrayP;
arrayP = (partinTable*) MemHandleLock(lookupTableHandle);
// now, either of the following statements are equivalent for
// accessing the fourth element of the array:
(*(arrayP+3)).gleasonMin = 0; // yuck!
arrayP[3].gleasonMin = 0; // much nicer!
Regarding the second question:
> // how do I assign these values to that array?
> // originally, this was just assigned like this...
> // static partinTable[NUMBER_PARTIN_ROWS] =
>
> { 2, 4, T1a, 0, 4, 90, 9, 0, 0 },
> { 2, 4, T1a, 4, 10, 84, 14, 1, 0 },
> ............ 140 rows of this.........
> { 2, 4, T1c, 20, 9999, 58, 34, 7, 1 },
> };
You can't have a static initialization list using this scheme.
Applying the previous syntax to this problem, you'll need an initialization
function to make the assigments. This unfortunately burdens the code
resource instead of the data resource which could be a problem if the
program is already large. There are resource size limits, but I still
don't know enough about Pilot Programming to respond intelligently.
The following part looks like an algorithm in "normal" code. Array
assignments work as described above.
>
> for ( i = 0; i < NUMBER_PARTIN_ROWS ; i++) {
> if (gleason >= lookup[i].gleasonMin && gleason <=
lookup[i].gleasonMax)
> if (tumorStage == lookup[i].tumorStage)
> if (psa >= lookup[i].psaMin && psa <= lookup[i].psaMax) {
> // if this is the right row, assign all scores
> wPPOCD = lookup[i].ocdScore;
> wPPECP = lookup[i].ecpScore;
> wPPSVI = lookup[i].sviScore;
> wPPLNI = lookup[i].lniScore;
> break;
> }
> } // end of for loop
>
> // MemUnlockHandle(lookupTableHandle)
I don't know if any of this helps or if you're already at this point
in your solution. Now for a question to you: I understand the concept
that you're applying. You're creating a relocatable block of data
so that you don't have some chunk that's pinned to a particular address.
My (compound) question is this: how or when do you decide that data is big
enough that it should be relocatable? I see many example programs
that have "normal" global variables (sometimes several of them!) that
do not bother with this strategy. Where did you find the discussion
about how to do this? (Or did you assimilate this solution from the
sparsely commented SDK docs?)
I'm very experienced at C++ coding for other platforms, including Windows,
and have worked with complex data structure algorithms for many years
(more than I'd care to admit). However, I'm still trying to climb
the learning curve for Pilot programming strategies!
Thanks, and good luck in your own programming endeavors.
Dave.
--
Dave Smith
Colorado Springs, CO USA