GameLoading
GameLoading

Reputation: 6708

a long long file reading

I want to read one text file and perform some action on that data.

file size is 67 mb

how can i read.

file is in text format.

its working in simulateor but giving memory warning in device and crashes.

code is

NSString *content = [[[NSString alloc] initWithContentsOfFile:fileName usedEncoding:nil error:nil] autorelease];

crashes when this sentence complete.

Thanks,

Shyam parmar

Upvotes: 1

Views: 159

Answers (3)

Erik S
Erik S

Reputation: 1929

Fasttracks, try what Peter suggested. The problem is loading it all at once, since you have about 20 MB available for your own app, i believe. If you'd use a NSInputStream, you can load it in pieces, due to which you wont fill up the entire memory at once. Also read this answer to another question: Objective-C: Reading a file line by line

Upvotes: 2

Peter DeWeese
Peter DeWeese

Reputation: 18343

You haven't given code, but if you are using stringWithContentsOfFile to get an entire file consider using NSInputStream or stdio to read it and process or display it more incrementally.

Upvotes: 3

Mikael
Mikael

Reputation: 3612

Do you start reading the file from - (void) viewDidLoad? That might be the problem. Try start reading it in a different thread, like: [self performSelectorInBackground:@selector(method) withObject:nil];

Upvotes: 1

Related Questions