我想知道如何在不使用输入输出到文件系统或外部数据库的情况下让存储容器在多个执行时间(运行)内不会丢失内容的最佳解决方案。跨越多次运行的持久存储
说我有一个类foo()存储整数。从main()我想调用一个方法来添加一个整数,并且类不会忘记其以前的内容。
//
// Data storage accross different runs
// This should go into the daemon process
//
#include<iostream>
#include<list>
using namespace std;
class foo {
public:
foo(int add): add(add) {}
void store(int i) {
vec.push_back(i + add);
}
private:
list<int> vec;
int add;
};
主函数应该检查一个已经运行的守护进程 - 如果没有启动它。
//
// Main program. Should check whether daemon runs already, if not starts it.
//
void main(int argc, char *argv[]) {
// if (daemon is not running)
// start daemon(some_number)
// call daemon::add(atoi(argv[1]));
}
如何最好地与共享库或守护进程做到这一点?存储和调用程序位于同一台Linux主机上。
这听起来很困难。你能告诉我们更多关于“多次运行”的含义吗?这些会有关系吗?他们会以紧密的顺序运行吗?使用小文件存储信息可能会更容易。 – 2011-05-12 13:38:02