ios - How to import a large text file containing many small records in Objective-C without using large amounts of memory -


Import some large files (100 MB +) into CoreData in an app targeting for mobile devices targeted for Merid The ability to do is constrained. Each file contains a large number of small records which will be processed before being added to the database. Searching from several sources is a recommended method of reading in a text file:

  NSString * stringFromFileAtPath = [[NSString alloc] initWithContentsOfURL: URL encoding: NSUTF8StringEncoding error: & amp; Error];   

At first glance it is necessary for me, it seems very intensively, but assuming that there is no other recommended way to read the file, let me guess It is true that Apple has kept this in mind and managing its memory - maybe a mistake in the data from the file when necessary?

If moving forward to use NSTrim and NSSCan and one line

];

If I use this method then I am assuming that it will need a complete text file in memory so that this memory is again intensive. Would it be better to use NSScanner to save memory or will it take forever to meet the limited processing power of mobile devices (definitely some older ones)?

Thank you in advance for any help with this question.

Dave

Memory-mapped files can be of a large file A good way to check the content and it looks like - [NSString initWithBytesNoCopy: length: encoding: free Javaden:] will make you an NSString which is memory-mapped I use the contents of the file as the value of the string directly

I have not used that particular function, I have to accept, but mine The app uses memory-mapped files and they were easy to work dead. So at least, you do not have to load 100 MB of data at a time, but there is a possibility of loading all the convenience of having 100 MB of data at one go.

Use the POSIX function to map a file in memory mmap You will need to handle a POSIX file, which is my code open ( After normal songing and dancing, after getting the UTF 8 copy of the correct file name in bundle), but probably also used one of the ns features.

Comments