@interface GenericRecord : NSObject <NSCopying>
{
NSMutableArray *record;
... plus a couple ivars not used for the sort
}
Field access is slower because you have to call two methods instead
of one - one of the generic recorder, and then the array
objectAtIndex method. Consider using instance variables.
Why use a mutable array? it takes more memory and slower then non
mutable array. Are your fields mutable?
For example, even if you wan to edit the table, you can make a
mutable copy of a record, edit it, and set the edited record back in
the generic record.
@interface GenericTable : NSObject <NSCoding>
{
NSMutableArray *records; // the records of data
... plus a couple ivars not used for the sort
}
// IN GenericTable implementation
- (void) sortRecordsByField: (int) fieldNum;
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //
experimental! initially ran without it...
NSArray *sortedArray;
void *i;
i = (void *) &fieldNum;
sortedArray = [records sortedArrayUsingFunction: sortGenericRecord
context: i]; // FROZE AFTER 20 MIN OF EXECUTION HERE
Here you just made a copy of the 100,000 records array, and you have
200,000 records...
// [self setRecords: [NSArray arrayWithArray: sortedArray]];
[self setRecords: [NSMutableArray arrayWithArray:
sortedArray]]; // DID NOT GET THIS FAR....
And here you do another copy; 300,000 records!
If you implement you setRecords: with copy - preventing someone from
modifying your table behind your back, you have now 400,000 records
in memory.