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


C++ Frame::GetPageID方法代码示例

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


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

示例1: FindFrame

//--------------------------------------------------------------------
// BufMgr::FindFrame
//
// Input    : pid - a page id 
// Output   : None
// Purpose  : Look for the page in the buffer pool, return the frame
//            number if found.
// PreCond  : None
// PostCond : None
// Return   : the frame number if found. INVALID_FRAME otherwise.
//--------------------------------------------------------------------
int BufMgr::FindFrame( PageID pid )
{
	Frame* currFrame;
	for (int iter = 0; iter < numFrames; iter++) {
		currFrame = &frames[iter];
		if (currFrame->GetPageID() == pid) {
			return iter;
		}
	}
	return INVALID_FRAME;
}
开发者ID:EthanRubinson,项目名称:Buffer-Manager,代码行数:22,代码来源:bufmgr.cpp

示例2: UnpinPage

//--------------------------------------------------------------------
// BufMgr::UnpinPage
//
// Input    : pid     - page id of a particular page 
//            dirty   - indicate whether the page with page id = pid
//                      is dirty or not. (Optional, default to false)
// Output   : None
// Purpose  : Unpin the page with page id = pid in the buffer. Mark 
//            the page dirty if dirty is true.  
// Condition: The page is already in the buffer and is pinned.
// PostCond : The page is unpinned and the number of pin on the
//            page decrease by one. 
// Return   : OK if operation is successful.  FAIL otherwise.
//--------------------------------------------------------------------
Status BufMgr::UnpinPage(PageID pid, bool dirty)
{
	//std::cout << "Unin PageID " << pid << std::endl;
	////std::cout << "Unpinning page  " << pid << " Dirty?: " << dirty << std::endl;
	int frameIndex = FindFrame(pid);
	if (frameIndex == INVALID_FRAME) return FAIL;

	Frame* targetFrame = &frames[frameIndex];
	if (targetFrame->NotPinned()) return FAIL;

	if (dirty) targetFrame->DirtyIt();

	targetFrame->Unpin();

	if (targetFrame->NotPinned()) replacer->AddFrame(targetFrame->GetPageID());

	return OK;
}
开发者ID:EthanRubinson,项目名称:Buffer-Manager,代码行数:32,代码来源:bufmgr.cpp

示例3: FlushPage

//--------------------------------------------------------------------
// BufMgr::FlushPage
//
// Input    : pid  - page id of a particular page 
// Output   : None
// Purpose  : Flush the page with the given pid to disk.
// Condition: The page with page id = pid must be in the buffer,
//            and is not pinned. pid cannot be INVALID_PAGE.
// PostCond : The page with page id = pid is written to disk if it's dirty. 
//            The frame where the page resides is empty.
// Return   : OK if operation is successful.  FAIL otherwise.
//--------------------------------------------------------------------
Status BufMgr::FlushPage(PageID pid)
{
	//std::cout << "Flush Page" << pid << std::endl;
	////std::cout << "Flush Page  " << pid << std::endl;
	int frameIndex = FindFrame(pid);
	if (frameIndex == INVALID_FRAME) return FAIL;

	Frame* targetFrame = &frames[frameIndex];
	if(!targetFrame->IsValid() || !targetFrame->NotPinned()) return FAIL;

	if (targetFrame->IsDirty()){
		if (targetFrame->Write() != OK) return FAIL;
		numDirtyPageWrites++;
	}
	
	replacer->RemoveFrame(targetFrame->GetPageID());
	targetFrame->EmptyIt();
	//std::cout << "Flush OK " << std::endl;
	return OK;
} 
开发者ID:EthanRubinson,项目名称:Buffer-Manager,代码行数:32,代码来源:bufmgr.cpp

示例4: FlushAllPages

Status BufMgr::FlushAllPages()
{
	//std::cout << "Flush all " << std::endl;
	bool failedOnce = false;
	Frame* currFrame;
	for (int iter = 0; iter < numFrames; iter++) {
		currFrame = &frames[iter];
		if (currFrame->IsValid()) {
			// Check that the frame is not pinned
			if (!currFrame->NotPinned()){
				failedOnce = true;
			}

			if (currFrame->IsDirty()){
				if (currFrame->Write() != OK) failedOnce = true;
				numDirtyPageWrites++;
			}

			replacer->RemoveFrame(currFrame->GetPageID());
			currFrame->EmptyIt();
		}
	}
	return (failedOnce) ? FAIL : OK;
}
开发者ID:EthanRubinson,项目名称:Buffer-Manager,代码行数:24,代码来源:bufmgr.cpp

示例5: PinPage

//--------------------------------------------------------------------
// BufMgr::PinPage
//
// Input    : pid     - page id of a particular page 
//            isEmpty - (optional, default to false) if true indicate
//                      that the page to be pinned is an empty page.
// Output   : page - a pointer to a page in the buffer pool. (NULL
//            if fail)
// Purpose  : Pin the page with page id = pid to the buffer.  
//            Read the page from disk unless isEmpty is true or unless
//            the page is already in the buffer.
// Condition: Either the page is already in the buffer, or there is at
//            least one frame available in the buffer pool for the 
//            page.
// PostCond : The page with page id = pid resides in the buffer and 
//            is pinned. The number of pin on the page increase by
//            one.
// Return   : OK if operation is successful.  FAIL otherwise.
//--------------------------------------------------------------------
Status BufMgr::PinPage(PageID pid, Page*& page, bool isEmpty)
{
	if(pid == INVALID_PAGE) return FAIL;

	totalCall++;

	// Check if the page is in the buffer pool
	bool inPool = false;
	Frame* currFrame;
	for (int iter = 0; iter < numFrames; iter++) {
		currFrame = &frames[iter];
		if (currFrame->GetPageID() == pid){
			inPool = true;
			totalHit++;
			break;
		}
	}

	if (inPool){
		// Increase its pin count and set output page pointer
		currFrame->Pin();
		page = currFrame->GetPage();
	}
	else {
		
		// Find the first free frame if there is one
		bool foundEmptyFrame = false;
		for (int iter = 0; iter < numFrames; iter++) {
			currFrame = &frames[iter];
			if (!currFrame->IsValid()){
				foundEmptyFrame = true;
				break;
			}
		}
		
		if (!foundEmptyFrame) {
		
			// Find a page to evict based on our replacement policy
			int replacedPageID = replacer->PickVictim();

			// Get a pointer to the frame we will flush
			for (int iter = 0; iter < numFrames; iter++) {
				currFrame = &frames[iter];
				if (currFrame->GetPageID() == replacedPageID){
					break;
				}
			}

			if(FlushPage(replacedPageID) != OK) { 
				page = NULL;
				return FAIL;
			}
		}

		currFrame->SetPageID(pid);
		currFrame->Pin();

		// If the page is not empty, read it in from disk
		if (!isEmpty && currFrame->Read(pid) != OK) {
			page = NULL;
			return FAIL;
		}
		

		page = currFrame->GetPage();
	}

	// Now that the frame is pinned we need to remove it from the ones that can be evicted
	replacer->RemoveFrame(currFrame->GetPageID());
	////std::cout << "pinned page: " << currFrame->GetPageID() <<std::endl;
	return OK;
} 
开发者ID:EthanRubinson,项目名称:Buffer-Manager,代码行数:91,代码来源:bufmgr.cpp


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