【发布时间】:2011-08-24 00:21:12
【问题描述】:
我想知道在不使用文件系统或外部数据库的输入输出的情况下,让存储容器在多个执行时间(运行)内不会丢失其内容的最佳解决方案是什么。
假设我有一个存储整数的类 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 主机上。
【问题讨论】:
-
这听起来很难。你能告诉我们更多关于“几次运行”的意思吗?这些会有关系吗?他们会按顺序运行吗?使用小文件存储信息可能更容易。
标签: c++ shared-libraries daemon