示例#1
0
//---------------------------------------------------------------
void reference(int procNum, int  vpn)
{
  currProcIdx = getValidProcIndex(procNum, 0);

	// if( page number is out of bounds )
	if(vpn < 1 || vpn > getAddrSpaceSize(currProcIdx)){
		fprintf(stderr, "[Error] Page number out of bounds\n");
		fprintf(stderr, "        Please use a valid input file\n");
		cleanUp();
		exit(1);
	}
	
	// if( page is not in memory )
	if(!pageInMem(currProcIdx, vpn)){
		// if( memory is full )
		if(!freePages){
			// evict a page
			switch(policy){
				case 0: replaceLRU(); break;
				case 1: replaceRandom(); break;
				case 2: replaceNFU();
			}
		}
		
		storePage(currProcIdx, vpn);
		
		numFaults++;
	}
	
	updateHistory(procNum, vpn);
	
	numRefs++;
	if(DBG) printf("Free frames: %d\n", freePages);
	if(DBG) printf("Faults( %d ), References( %d ) -> Fault rate( %.4f )\n\n", numFaults, numRefs, (double)numFaults/numRefs);
}
示例#2
0
 void set(int key, int value) {
     // Cache value for given key could be updated!
     unordered_map<int,LI>::const_iterator it = key2addr.find(key);
     if(it != key2addr.end())
     {
         refreshEntry(it->second, value);
     }
     else
     {
         if(size == cap)
             replaceLRU(key, value);
         else
         {
             LRUlist.push_front({key,value});
             key2addr[key] = LRUlist.begin();
             size++;
         }
     }
 }