解析大型 PLIST 和内存占用
在这个问题(http://stackoverflow.com/questions/1267474/itunes-xml-parsing-in-cocoa)中,Sreelal 询问如何提高加载/解析大型 PLIST 的性能。然而,这个问题从未得到真正的答案(尽管亚历克斯给出了一些非常有用的指示)。
Peter Hosey 指出,即使 PLIST 被解析而不是转储到 NSDictionary 中,整个文件也会加载到内存中。
在 Cocoa 应用程序中,我正在使用 Aperture 库,它们也有大型 PLIST 文件。获得良好性能(速度)并且不让您的应用程序占用所有系统内存的最佳方法是什么?
NSXMLParser 是一个好方法吗?如果可能的话,我更愿意坚持使用苹果自己的框架。
谢谢
In this question (http://stackoverflow.com/questions/1267474/itunes-xml-parsing-in-cocoa), Sreelal asks how to improve performance of loading/parsing a large PLIST. The question, however, never got a real answer (although some very useful pointers were given by Alex).
Peter Hosey pointed out that the whole file does get loaded into memory even when the PLIST is parsed instead of dumped into a NSDictionary.
In a Cocoa application, I am working with Aperture libraries and they too have large PLIST files. What is the best approach to have good performance (speed) and not having your app taking up all the system's memory?
Is NSXMLParser a good approach? I prefer to stick to Apple's own frameworks if possible.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当处理大文件时,我会结合使用 NSXMLParser 和 NSFileHandle 这允许您一次加载部分数据,而无需一次将其全部加载到内存中。 Apple 在developer.apple.com(如果您是注册开发者)上有一个完整的 WWDC 视频,名为“iPhone OS 上的高级性能优化”。他们建议您不要对非常大的文件使用 PLIST 格式,但他们随后讨论了如何分部分加载文件,然后您可以使用 NSXMLParser 将它们分成小部分(甚至可以分为多个线程)。希望这有帮助!
When messing with large files I would use a combination of NSXMLParser with NSFileHandle this allows you to load parts of the data at a time without loading it all at once into memory. Apple has an entire WWDC video on developer.apple.com (if your a registered developer) called Advanced Performance Optimizations on iPhone OS. In that they recommend you don't use the PLIST format for extremely large files but they then discuss how you can load files in parts which you could then use NSXMLParser to parse them in small parts (which could even be divided into several threads). Hope this helps!