views:

44

answers:

2

I have a plist (array of dictionaries) with 20 items, each of the 20 dictionaries having a 'code' and 'text'; each text averages 1K bytes. The class that uses the text will use 1 of the 20, based on the 'code'. The text doesn't change so I'm keeping it in the bundle.

I'd like to know if I'm doing this as efficiently as possible, basically reading in 20K of data for a second, using what I need and releasing all but the 1K that I use.

I have 2 ivars without properties:

NSMutableArray *explanation;
UITextView *textView;

The textView is in a UITableViewCell and from the cellForRowAtIndexPath I call [self retrieveExplanation]. I load the textView from within retrieveExplanation rather than returning an NSString, to save the additional NSString memory allocation.

-(void) retrieveExplanation {
    explanation = [[NSMutableArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"explanation"ofType:@"plist"]];
    textView.text = [[explanation objectAtIndex:[self.itemNumber intValue] - 1] objectForKey:@"text"]; 
    [explanation release];
}

Can this be more efficient? Should I consider using 20 plists or text files?

Thanks

A: 

I think you should think carefully about this problem. How long does it take a normal iPhone to load all of your 20K text. If it is really slow, you may need to consider to separate the text file out.

The problem when you separate them out is how you can manage a large number of text files. I don't really recommend you to separate to 20 text files, it seems too much overhead to manage all of them comparing to the performance we can get back.

I can suggest you to separate to 4 text files, so at least the performance will go up 4 times. If it runs quickly enough (< 1s for example), then your job is done. If it is not, then you need to separate more

vodkhang
Thanks. I went with the 'balance optimal number/size of files against an acceptable load time' approach.
Matt Winters
A: 

This sort of stuff is really hard to be definitive about. You can give advice but the "truth" is best determined by trying out different approaches and measuring the amount of time used.

All I can suggest is try out some ideas of the ideas that you have and get some hard numbers.

Also, make sure that you measure on the device and not through the simulator.

No one in particular