我有一个带有成员clientCache的类:
public:
LRUCache<string, string>* clientCache;
缓存由以下方式启动:
clientCache = new LRUCache<string, string>(3);
//Reset cache to stored values if exist:
ifstream ifs(this->cachePath.c_str(), ios::binary);
// Verify that file exists
if(ifs.good()){
ifs.read((char *)&this->clientCache, sizeof(this->clientCache));
printf("Persistent cache file loaded");
}
在析构函数中:
ofstream ofs(this->cachePath.c_str(), ios::binary);
ofs.write((char *)&this->clientCache, sizeof(this->clientCache));
printf("Persistent cache file written with:");
printf((char*)&this->clientCache); //-> Nothing gets printed
尝试加载回上一步写入的文件失败:
ifstream ifs(this->cachePath.c_str(), ios::binary);
// Verify that file exists
if(ifs.good()){
ifs.read((char *)&this->clientCache, sizeof(this->clientCache));
printf("Persistent cache file loaded");
}
打印输出真的应该是空的吗?这是不是保存失败的信号。LRUCache 类的内容(方法/成员)是否重要,即如果我尝试存储所有键值而不是整个实例的数据,我会更成功吗?