从iPhone的Documents文件夹中读取/写入 [英] Reading/Writing to/from iPhone's Documents folder performance

查看:173
本文介绍了从iPhone的Documents文件夹中读取/写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone应用程序,在其中我将永久性数据存档在该应用程序的documents文件夹中(数组,字典).我经常在document文件夹中读写文件,我想知道这是否被认为是一种坏习惯.如果我有一个单例类,在那儿读写数组,然后仅在应用程序退出时将此数据写到documents文件夹,这会更好吗?我现在在iPhone 5上没有看到/感觉到任何性能问题,但是我想知道这是否是一个坏习惯.

I have got an iPhone application where I archive permanent data in the documents folder of the application (arrays, dictionaries). I read/write from and to the documents folder quite frequently and I would like to know whether this is considered a bad habit. Wouldn't it be better if I had a singleton class, read and write to arrays there and then, only when the application quits, write this data to the documents folder ? I do not see/feel any performance issues right now on my iPhone 5, but I wanted to know whether this is a bad practise.

推荐答案

FLASH存储器具有有限的写能力-很久以前,它的评估等级为数千.不知道今天在哪里.

FLASH memory has limited write capability - a long time ago it was rated in some increment of thousands. Not sure where it is today.

也就是说,如果您的应用程序使用标准文件系统API,则系统正在使用文件缓存,您可以打开文件,读取文件,然后对其进行多次更改,而无需将文件系统写入闪存.系统有时可能会同步闪烁,但是该过程是不透明的-无法真正知道iOS何时或为何这样做.

That said, if your app is using the standard file system APIs, then the system is using the file cache, and you might open a file, read it then change it many times without the file system ever writing to flash. The system may sync to flash occasionally, but that process is opaque - no way to really know when or why iOS does it.

UNIX API允许将文件系统高速缓存同步到存储系统(iOS,这是FLASH),但是如果您不使用它,那么按照上述内容,您可能根本没有做太多的I/O.

The UNIX APIs allow for syncing the file system cache to the storage system (iOS this is FLASH), but if you are not using that then you are probably not doing much I/O at all given what you say above.

鉴于苹果公司缺乏劝阻开发人员编写文件系统的知识,我肯定不会为此担心.

Given the lack of Apple discouraging developers from writing to the file system, I for sure would not worry about this.

但是,如果您说您每隔几分钟就会写入千兆字节的图像数据-那么-这可能是个问题.

But, if you said you were writing gigabytes of image data every few minutes - well - that might be a problem.

这篇关于从iPhone的Documents文件夹中读取/写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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