is it a problem to write a file thousands of times on iOS?

In an iOS app: consider the use case of having a small amount of very volatile data that I want to persist (so the app can get the last version when it restarts). A stock tick, game position, some counter, last keystroke, etc. This value can change 1,000's times in one app session (or more: 100,000's of times I guess).


I'd like to persist that one simple value in its own file, for other reasons. If I use the standard file writing mechanisms (perhaps using FileHandle), will this be ok to overwrite the same file so many times?


I know that it's bad to write thousands of times to the same actual hardware flash memory - that'd burn out the device.


But will iOS/file-apis solve this for me? Like through caching or memory mapping or something?


just checking, thanks!

Replies

Writing to a data file is common enough. I doubt the frequency matters, generally, as long as you're willing to settle for any inherent fragility related to high frequency updates, etc.

Don't worry about it. There is no way you would ever match Apple's logging writes.

What you are proposing is poor programing, IMHO. Store this information in (volatile) memory not a file. Move it from memory to a file when the app executes applicationDidEnterBackground. If you want to have it available everywhere in the app then use a static Model (in MVC programming) or pass it to those viewControllers that need the information.


Actually, what you seem to want is done automatically by NSUserDefaults. It stores stuff in memory and writes it to file only when the app synchs. And it is available throughout the app.