小编ati*_*ati的帖子

如何将C++类实例(使用STL容器)加载/保存到磁盘

我有一个C++类,表示一个非常大的分层组织数据树(~Gb,基本上和我在内存中可以消除的一样大).它使用STL列表在每个节点上存储信息,并在其他节点上存储迭代器.每个节点只有一个父节点,但有0-10个子节点.抽象,它看起来像:

struct node {
public:
    node_list_iterator parent;              // iterator to a single parent node
    double node_data_array[X];
    map<int,node_list_iterator> children;   // iterators to child nodes
};

class strategy {
private:
    list<node> tree;        // hierarchically linked list of nodes
    struct some_other_data;
public:
    void build();           // build the tree
    void save();            // save the tree from disk
    void load();            // load the tree from disk
    void use();             // use the tree
};
Run Code Online (Sandbox Code Playgroud)

我想将load()和save()实现到磁盘,它应该相当快,但明显的问题是:

  1. 我不提前知道尺寸;

  2. 数据包含迭代器,它们是易失性的;

  3. 我对C++的无知是惊人的.

请问有人建议使用纯C++解决方案吗?

c++ io serialization stl multiway-tree

6
推荐指数
1
解决办法
2609
查看次数

标签 统计

c++ ×1

io ×1

multiway-tree ×1

serialization ×1

stl ×1