当前位置: 首页>>代码示例>>C++>>正文


C++ VNode::isDirty方法代码示例

本文整理汇总了C++中VNode::isDirty方法的典型用法代码示例。如果您正苦于以下问题:C++ VNode::isDirty方法的具体用法?C++ VNode::isDirty怎么用?C++ VNode::isDirty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VNode的用法示例。


在下文中一共展示了VNode::isDirty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: flush

//NOTICE:this can only be done by one thread
//write out all the elements to hard disk. 
bool LRUCache::flush()
{
#ifdef DEBUG_VSTREE
	cout<<"to flush in LRUCache"<<endl;
#endif
	FILE* filePtr = fopen(this->dataFilePath.c_str(), "r+b");

	if (filePtr == NULL)
	{
		cerr << "error, can't open file. @LRUCache::flush" << endl;
		return false;
	}

	int startIndex = LRUCache::DEFAULT_NUM;
	int endIndex = startIndex + this->size;
	size_t vNodeSize = VNode::VNODE_SIZE;
	//size_t vNodeSize = sizeof(VNode);

	//NOTICE:values are continuous
	for (int i = startIndex; i < endIndex; ++i)
	{
		VNode* nodePtr = this->values[i];
		int line = this->keys[i];
		//cout<<"file line to write "<<line<<endl;

#ifdef DEBUG
		if (nodePtr->getFileLine() != line)
		{
			cout << "line error at !!!" << line << " " << nodePtr->getFileLine() << endl;
		}
#endif

		if (nodePtr == NULL)
		{
			cerr << "error, VNode do not exist. @LRUCache::flush" << endl;
			return false;
		}

		if(!nodePtr->isDirty())
		{
			continue;
		}

		int flag = 0;
		long long seekPos = (long long)line * vNodeSize;
		flag = fseek(filePtr, seekPos, SEEK_SET);

		if (flag != 0)
		{
			cerr << "error, can't seek to the fileLine. @LRUCache::flush" << endl;
			return false;
		}

		//fwrite((char *)nodePtr, vNodeSize, 1, filePtr);
		nodePtr->writeNode(filePtr);
	}
	fclose(filePtr);

	return true;
}
开发者ID:summercyy,项目名称:gStore,代码行数:62,代码来源:LRUCache.cpp

示例2: fopen

//just write the values[_pos] to the hard disk, the VNode in memory will not be free. 
bool 
LRUCache::writeOut(int _pos, int _fileLine)
{
	VNode* nodePtr = this->values[_pos];
	FILE* filePtr = fopen(this->dataFilePath.c_str(), "r+b");

	if (nodePtr == NULL)
	{
		cerr << "error, VNode do not exist. @LRUCache::writeOut" << endl;
		return false;
	}
	if (filePtr == NULL)
	{
		cerr << "error, can't open file. @LRUCache::writeOut" << endl;
		return false;
	}

	if (nodePtr->getFileLine() != _fileLine)
	{
		cerr << "error, fileLine " << _fileLine <<" "<< nodePtr->getFileLine() << " wrong. @LRUCache::writeOut" << endl;
	}

	if(!nodePtr->isDirty())
	{
		//cout<<"the node not dirty!"<<endl;
		fclose(filePtr);
		return true;
	}
	else //is modified
	{
		nodePtr->setDirty(false);
	}

	int line = _fileLine == -1 ? nodePtr->getFileLine() : _fileLine;
	size_t vNodeSize = VNode::VNODE_SIZE;
	//size_t vNodeSize = sizeof(VNode);
	int flag = 0;
	long long seekPos = (long long)line * vNodeSize;

	flag = fseek(filePtr, seekPos, SEEK_SET);

	if (flag != 0)
	{
		cerr << "error, can't seek to the fileLine. @LRUCache::writeOut" << endl;
		return false;
	}

	//fwrite((char *)nodePtr, vNodeSize, 1, filePtr);
	nodePtr->writeNode(filePtr);
	fclose(filePtr);

	return true;
}
开发者ID:summercyy,项目名称:gStore,代码行数:54,代码来源:LRUCache.cpp


注:本文中的VNode::isDirty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。