4

If you have a giant static const array (say, several tens of megabytes) that never changes and is only used at startup, is it automatically paged out when memory is scarce? That is, does iOS know that your static const data can simply be reloaded from your app's bundle?

The obvious alternative is to put that data in a file and either memory-map it as readonly data (which is definitely automatically paged out) or read it into a malloc'd buffer and release it when done — but is that more work than is necessary in this case?

Todd Lehman
  • 2,880
  • 1
  • 26
  • 32

1 Answers1

1

The implementation of iOS memory management is not documented, and subject to change with OS updates. I would not depend on undocumented behavior for anything important. Is there any reason you couldn't store your data in SQLite (I'm a fan of YAPDatabase, but any DB would work) and query it as needed? That would keep your memory usage down and make the app feel much snappier.

RyanR
  • 7,728
  • 1
  • 25
  • 39
  • What I have is just a simple static const array that I use to populate an open-addressing hash table at startup. (I *could* hard-code the hash table instead of programmatically populating it, but I want to experiment with different hashing functions to tune it.) So while an SQLite database would *work*, it's probably even more effort than just reading a file, no? – Todd Lehman May 26 '15 at 20:14
  • 1
    I'm not certain what an 'open-addressing hash table' is - I'm guessing you're doing address completion in a text field? Regardless, in my experience having a bunch of data fixed in memory that is not in constant use and that is immediately filtered when its needed results in Bad Things (tm). Any time I've done an autocomplete field I've used SQLite and its performance has been perfectly fine (nobody has ever said 'this text field is slow to auto-complete'). – RyanR May 26 '15 at 22:24