1) As suggested by someone, I took my comparison routine and replaced it
with
static Int SortEm(CatalogDBRecordPtr r1, CatalogDBRecordPtr r2, int
sortOrder,
SortRecordInfoPtr sr1,
SortRecordInfoPtr sr2, VoidHand appInfoH)
{
return(0);
}
This succeeds with >16384 records. I'm not sure what this proves because
since there is no shuffling going on, it may simply never get to the
point that it does when it is really sorting the data. Interestingly
enough, however, the data ARE re-sorted; don't ask me how or by what
criteria this is happening.
2) I next went to this:
static Int SortEm(CatalogDBRecordPtr r1, CatalogDBRecordPtr r2, int
sortOrder,
SortRecordInfoPtr sr1,
SortRecordInfoPtr sr2, VoidHand appInfoH)
{
Char theChars[32];
StrCopy(theChars,&r1->info);
StrCopy(theChars,&r2->info);
return(0);
}
This still returns zero (and hence doesn't sort), but tests whether the
record ptrs (r1 and r2) being supplied to the comparison routine are
valid. Evidently they are because this succeeds as well.
3) Now return the real answer...
static Int SortEm(CatalogDBRecordPtr r1, CatalogDBRecordPtr r2, int
sortOrder,
SortRecordInfoPtr sr1,
SortRecordInfoPtr sr2, VoidHand appInfoH)
{
Char theChars[32];
StrCopy(theChars,&r1->info);
StrCopy(theChars,&r2->info);
return(StrCompare(&r1->info,&r2->info));
}
This now crashes, "DataMgr.c Line 8589 Index out of range" (different
line number than I reported before because this test was with PalmOS
3.5). And, I confirm (via having a message displayed when the sort is
finished) that the sort does NOT finish, that is, the crash is not due to
my app behaving incorrectly post-sort, but due to the sort itself.
Judging from the time it does always seem to make it MOST of the way
through the sorting process, just not all the way through. This
undoubtedly relates to the way the algorithm works, as alluded to by
someone.
4) And now the good news (sort of)...
Switching from DmQuickSort to DmInsertionSort works (i.e., does not
crash)! :-) The success, unfortunately, does come at a price (as
suggested in the docs). Sorting 16051 records (a number which works with
both types of sorting) via DmInsertionSort two different ways took (for
this particular database and these methods of sorting) 4:30 and 4:19
(interestingly enough it took >7:00 for 16600 records, so something seems
to happen over that 16384 mark which seriously degrades performance).
Using DmQuickSort it took 2:22 and 1:29. So it appears that a
if (DmNumRecords(...)>16383) DmInsertionSort(...) else DmQuickSort(...)
is now required everywhere in my code where a DmQuickSort appears. Alas.
And for David's sake :-) may I say that I consider the change in behavior
by simply switching one line of code (from DmQuickSort crashing to
DmInsertionSort not crashing) is pretty good confirmation of a bug in the
OS.
Steve Patt
President, Stevens Creek Software
http://www.stevenscreek.com/palm
Best PQA ("ePQA"), PalmSource 99
Best Application ("PizzaScan"), Palm Developer's Conference 1998
First printing software for the Palm - September, 1997
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html