开发者

Best strategy to read file only once at launch?

开发者 https://www.devze.com 2023-04-08 06:21 出处:网络
I am reading a file datafile at the launch of my application.This is just self learning drill. On apple developers website under the heading Minimize File Access at Launch Time

I am reading a file datafile at the launch of my application.This is just self learning drill.

On apple developers website under the heading Minimize File Access at Launch Time it says

If you must read a file at launch time, do so only once.

So my question is that is there a standard or preferred way of doing this. At the moment I have an instance varible NSArray and I populate that in - (void)viewDidUnloadand never garbage collect it. Is that good enough ? or Should I be making use of appl开发者_JAVA技巧ication Object (I am not even sure if it is logical to say this.).


There is no standard way to optimize. But there are some guidelines.

One basic idea of optimization is to do less. E.g. as the advice you cited where the data of a file may be needed at multiple points in your code, it is better to read it from disk once and then distribute a data pointer within your program.

If the file is big enough to cause a stutter when you start your application, i.e. it takes more than 20ms to read and parse the file, you should consider reading the file in a background thread/task and adding a ‘loading…’-state to display to the user.

0

精彩评论

暂无评论...
验证码 换一张
取 消