05-05-2011 11:49 AM
I have created applications that use persistent storage, and I have created applications that use an SQLite database. I have also created applications that use both. My question is this:
Should persistent storage be limited in what it stores? For example, should persistent storage be used more for purposes of storing simple things such as "the user's selected font size for the application" and "a hashtable of a default language and its language code for the application"? Or, might it also be recommended to act almost as a database, for example when a user doesn't have an SDCard installed - in which case you would store many vectors of objects and such?
Is there a possibility of persistent storage not being available due to limited space? For example, if the user has a lot of other applications that use up the persistent storage?
Finally, I believe that persistent storage is only erased in events of a battery pull, etc. Is it also possible for it to erase in other ways, like a restart?
Solved! Go to Solution.
05-05-2011 02:09 PM
I would look at the characteristics of the data I am storing and the characteristics of the options (SQLite, file on SD Card or PeristentStore) and make a decision based on that.
The key characteristics for me are
a) Size of data
b) Requirement for presence
c) Use of data
d) Removal of data
Working through these:
There is a reasonable amount of PeristentStore available, even only older devices. If you had a Vector of 10,000 Strings, each 100 bytes long, that is still only ! Mb of storage. And there are low storage managers that you can listen for and tidy up your use of PersistentStore. But there is more space on an SD Card, and no chance of you screwing the Blackberry is you use up too much memory (if you over use PersistentStore the device will clear out things like old emails which might upset your users).
Remember your users can pull the SD Card, and all the data
c) Use of data
If the data lends itself to be used an an Object fashion, then it seems appropriate way to store it in that form, which means there is no 'serialization' required to turn it into a flat file or conversion to turn it into a table. But things like images, sound files and the like gain no advantages being stored as an Object. So stick them on the SD Card.
PersistentStore is removed when the application is removed, which can be a good thing.
In summary, there no right answer here, use the best option for the job you have.
Regarding your questions:
"Is there a possibility of persistent storage not being available due to limited space?"
Yesish, as mentioned, there is the low storage manager. But to be honest, you could store megabytes of data in a table like structure in PersistentStore, and as long as you are careful, this will work fine.
"I believe that persistent storage is only erased in events of a battery pull"
No, it stays over a battery pull. To erase, the usual ways are to wipe the device, or remove the application that uses it.
05-06-2011 09:31 AM
I thank you for the very thorough answer. I found your section on "Size" particularly helpful. There are certainly a lot of factors to take into consideration with storage, and that is apparent from your response. After digesting this information during my daily run, I've decided to use a database when the SDCard is present, and PersistentStorage when it is not. I'm not going to use PersistentStorage heavily to store relational data, however, instead I am going to store some basic information and do more requests to my webservice to retrieve the detailed data.
Your help is always appreciated.