So I have 0.5MB XML file with data for my iPhone application. It’s all read-only so I don’t have to bother with writing.
Currently I’m using NSXMLParser to load data.
I had fun with NSXMLParser and I created a class that loads only the part of data that I currently need. So once the file is parsed it takes minimum of memory.
But it’s very slow. It takes 500-1000ms to parse the XML file and find the part of data that I need on my iPad.
I could load all the data at once and than just use it. That would definitely save me from all the XML loading and parsing, but then I would have 500kB NSArray or something. I don’t particularly like that idea.
I was wondering if there’s any way to do this that wouldn’t take much memory and would be fast too.
Any ideas please?
Updates:
Thanks everyone for answers. So it looks like these two options are the best for this case:
- Archiving XML data into binary form. It will be processed very quickly, and 500kB is really not that much to stay in the memory.
- If I really wanted to make it super-memory-efficient, than there’s SQLite or Core Data.
I think I’m gonna try and implement number one.
500 KB really is not that much. To put it in perspective, loading a full screen image as a background on your iPad uses 2.9 MB.
So, personally I would just load all data in memory and operate it directly.
I would also convert from XML to an archived NSArray or NSDictionary. That should make the initial loading very very fast.