简体   繁体   English

将C ++映射结构保存到磁盘

[英]saving C++ map structure to disk

I have a C++ map based structure that I'd like to save onto an ext3 based flash disk running Android. 我有一个基于C ++映射的结构,我想保存到运行Android的基于ext3的闪存盘上。 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)? 保存“基本”对象(大约有数百个条目)的好方法是什么?

  1. database (sqlite3) accessed through Android JNI 通过Android JNI访问的数据库(sqlite3)
  2. object serialization (boost) 对象序列化(提升)
  3. save as XML or JSON file 另存为XML或JSON文件
  4. 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. 最坏的情况是您有两个有效文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM