在iOS中高效存储大量数据 [英] Efficient storage of large amounts of data in iOS

查看:233
本文介绍了在iOS中高效存储大量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个具有记录功能的应用程序,该功能可记录用户随时间的交互。随着时间的推移,我用一个表示用户输入当前状态的状态对象填充内存中的数组。典型的记录将导致大约5k这些对象。

I'm building an application which has a "record" feature which records user interaction over time. As time progresses, I fill an array in memory with "state" objects representing the current state of the user input. A typical recording will result in about 5k of these objects.

然后我使用 NSKeyedArchiver archiveRootObject:toFile:。这工作正常,但文件大小非常大(3.5兆左右)。我的问题是:

I then archive this data using NSKeyedArchiver archiveRootObject: toFile:. This works fine, however the file size is very large (3.5 megs or so). My question is this:

归档文件是否涉及固有的文件大小开销?如果我使用SQLite,甚至滚动我自己的文件格式,是否可以使用更少的磁盘空间来保存这些数据?或者是减少数据磁盘大小的唯一方法是减少我存储的数字的位深度?

Is there any inherent file-size overhead involved in archiving files? Would I be able to save this data using much less disk space if I were to use SQLite, or even roll my own file format? Or is the only way to reduce the disk size of the data going to be to reduce the bit depth of the numbers I'm storing?

推荐答案

3.5 MB不是一个非常大的文件。但是,如果您的应用程序必须始终加载或保存3.5 MB文件,那么使用Core Data会更加智能,因为这样您只能保存已更改的数据并仅检索您感兴趣的部分 - - 不是每次都是全部。

3.5 MB isn't a very large file. However, if your app has to load or save a 3.5 MB file all the time, then using Core Data is a lot smarter as this allows you to save only the data that has changed and retrieve only the parts that you're interested in -- not the whole thing every time.

这篇关于在iOS中高效存储大量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆