want to open a large text file and then search the content of it. I loaded the file with stringWithContentsOfFile into a NSString. Every thing works on a 30mb file. But I am concerned what happens if I load a 200mb file, which I want to do. Is the complete NSString in the memory? if so it wouldn't work on iPhone. is there a solution for such large files on the iPhone?
Asked
Active
Viewed 470 times
0
-
Instead of your using text files you can use sqlite database and use core data to do your query. Its fast and efficient. – Robin Aug 18 '11 at 11:59
-
opening a file doesn't cost anything... reading and buffering does – Grady Player Feb 08 '14 at 02:42
2 Answers
1
A good way to read a large file would be to buffer small chunks of it at a time.
Not sure of the exact API methods you could use to do this, but it is fairly standard practice for audio, video, etc to read a small amount of the file into memory, process this, and remove it from memory as you continue through the file.

Jordan Smith
- 10,310
- 7
- 68
- 114
-
1See the second answer here for some sample code of how you might be able to do this: http://stackoverflow.com/questions/1044334/objective-c-reading-a-file-line-by-line – Jordan Smith Aug 18 '11 at 22:13
-
Note the obj c file classes are implemented using the classic C file functions which you can also use. – Sulthan Feb 08 '14 at 01:42
0
Since the limit isn't documented the way to check would be actually profiling it on target. People may be able to give their limits here but that is totally relative. Also a good memory management scheme and design would help you avoid problems of running out of memory.

Praveen S
- 10,355
- 2
- 43
- 69
-
The iPhone 4 has 512MBs of RAM, so that 200MBs would be almost half. Then you have the system and background apps—it's gonna be tight. And earlier devices don't have 512. – FeifanZ Aug 18 '11 at 12:48
-
@Inspire48: Yup that's the reason i have mentioned there is no definite limit. The phone may start howling when you allocate 10 mb(from personal experience) but if you manage well using the techniques suggested in documentation and few answers here you may be able to still write the app handling large amounts of data. – Praveen S Aug 18 '11 at 12:56