开发者

a long long file reading

I want to read one text file and perform som开发者_Go百科e 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


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.


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


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];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜