I have a C++ map based structure that I’d like to save onto an ext3 based flash disk running Android. The structure looks like this:
class kvBucket {
...
map<string, kvBucket*> buckets;
map<string, string> keyPairs;
...
}
class kvTree {
...
kvBucket base;
...
}
What’s a good way to save the ‘base’ object (which has about a few hundred entries)?
- database (sqlite3) accessed through Android JNI
- object serialization (boost)
- save as XML or JSON file
- something else
One consideration is that it needs to be crash proof, so if someone pulls the plug on the device while writing to disk, I need to recover gracefully.
Any of these solutions would be great.
If you want it to be crash-proof, do your writing to a temporary file, and only replace the original file after the write is complete. The worst scenario is that you have two valid files.