读取NSUserDefaults与变量的速度 [英] Speed of reading NSUserDefaults vs variables

查看:45
本文介绍了读取NSUserDefaults与变量的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它经常调用变量.这些变量存储在 NSUserDefaults 中.

I have an app and it calls to variables often. And these variables are stored in NSUserDefaults.

我想知道 NSUserDefaults 存放在哪里?如果我直接调用 NSUserDefaults 而不是使用变量.

I'm wondering where NSUserDefaults is storing? And if I call NSUserDefaults directly instead of using variables.

哪个更快?变量或 NSUserDefaults .因为使用变量存储 NSUserDefaults 将是使用更多内存的原因.

Which is faster? variables or NSUserDefaults. Because using variables to store NSUserDefaults will be the cause of using more memory.

推荐答案

NSUserDefaults 将其数据保留在磁盘上,因此在某些时候必须从磁盘加载该数据才能将其存储在内存中.当您告诉它同步时,它将需要将其写回到磁盘.

NSUserDefaults persists its data on disk so at some point it must load that data from disk in order to store it in memory. It will need to write it back to disk when you tell it to synchronize.

一旦在内存中,它将把它存储在类似字典的容器中(可能是 NSMutableDictionary ).

Once in memory, it will store it in a dictionary-like container (probably NSMutableDictionary).

与直接读取变量相比,从两个磁盘读取都非常昂贵,与读取变量相比,从字典中读取则非常昂贵.

Reading from both disk is very expensive compared to reading a variable directly and reading from a dictionary is moderately expensive compared to reading a variable.

从长远来看,它可以更快地读取/写入变量.

Reading/writing variables it much quicker by a long way.

这篇关于读取NSUserDefaults与变量的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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