iPad 文件写入性能

发布于 2025-01-02 09:13:14 字数 405 浏览 2 评论 0原文

我们有一个 POS 公寓租赁 iPad 应用程序,用于收集有关用户及其兴趣的大量数据(当然是他们的知识)。

我们使用 RestKit 将 CoreData 与服务器同步,这非常贴心。

我想做的是拥有一个备份系统,这样如果核心数据阻塞,并且我记录的堆栈跟踪不包含我需要的数据,我仍然可以以某种方式保存数据。我不想丢失数据。

因此,我在这里所做的是将用户数据写入除 CoreData 之外的磁盘上的文件中,并在会话结束时(如果没有出现问题)擦除该文件。如果出现问题,当应用程序再次启动时,它会与堆栈跟踪一起发送到 HockeyApp。

所以我的问题是性能之一。在影响性能之前,我可以多久写入一次此文本文件?这个应用程序中有很多屏幕,他们可以在输入信息时翻阅。他们可以很快地寻呼,我不希望它造成延误。这是我应该考虑的事情还是我已经离题了?

We have a POS apartment leasing iPad app that is used to collect a lot of data about a user and their interests (with their knowledge of course).

We use RestKit to sync CoreData with the server, which is totally sweet.

What I'm trying to do is have a backup system so if Core Data chokes, and my recorded stack trace doesn't contain the data I need, I still have the data saved somehow. I never want to lose data.

So what I'm doing here is writing the user data to a file on disk in addition to CoreData, and wipe the file when the session ends if nothing went wrong. If something does go wrong, it is sent along with the stack trace to HockeyApp when the app launches again.

So my question is one of performance. How often can I write to this text file before it affects performance? There are a bunch of screens in this app that they can page through as they enter information. They could page pretty quickly, and I don't want it to cause delays. Is that something I should consider or am I way off?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

源来凯始玺欢你 2025-01-09 09:13:14

最终,您必须量化写入操作的大小和复杂性。

无论如何,是什么阻止您使用 C 库,或者更具体地说,更典型的 C 方法?以下是您经常看到的方法的差异:

  • C:对于每个更改,将一些字节附加到文件
  • ObjC:对于每个更改(设置),创建所有内容的属性列表或存档。将所述属性列表完整写入磁盘。

使用较低级别的 CF/NS IO 类型也可以采用增量方法。值得注意的是:

  • NSFileHandle
  • NSOutputStream
  • CFWriteStream

这些类型能够进行同步和异步写入。

无论如何 - 如果您有大量数据要写入并在每个事务上重新格式化为属性列表,那么您应该考虑增量写入。

Ultimately, you must quantify the size and complexity of a write operation.

Anyways, what's stopping you from using C libraries, or more specifically the more typical C approach? Here's the difference in approaches you often see:

  • C: For each change, append some bytes to the file
  • ObjC: For each change (set), create a property list or archive of all the stuff. Write said property list in its entirety to disk.

The incremental approach is also possible using lower level CF/NS IO types. Notably:

  • NSFileHandle
  • NSOutputStream
  • CFWriteStream

These types are capable of sync and async writes.

At any rate - if you have a lot of data to write and reformat to a property list upon each transaction, then you should consider incremental writes instead.

分开我的手 2025-01-09 09:13:14

您可以测试一些东西来确定性能,但最重要的是,您的文件写入和其他非 UI 工作可以线程化(请参阅 NSThreadNSOperation参考)。将此工作放入后台线程有助于确保在主线程上运行的应用界面不会显得变慢。

You can test things to determine performance, but above all else, your file writes and other non-UI work can be threaded (see NSThread or NSOperation references). Putting this work into background threads helps ensure that your app's interface, which runs on the main thread, should not appear to slow down.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文