實(shí)驗(yàn)七頁面置換算法的模擬實(shí)現(xiàn)報告_川農(nóng)_第1頁
實(shí)驗(yàn)七頁面置換算法的模擬實(shí)現(xiàn)報告_川農(nóng)_第2頁
實(shí)驗(yàn)七頁面置換算法的模擬實(shí)現(xiàn)報告_川農(nóng)_第3頁
實(shí)驗(yàn)七頁面置換算法的模擬實(shí)現(xiàn)報告_川農(nóng)_第4頁
實(shí)驗(yàn)七頁面置換算法的模擬實(shí)現(xiàn)報告_川農(nóng)_第5頁
已閱讀5頁,還剩1頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、實(shí)驗(yàn)7 頁面置換算法的模擬實(shí)現(xiàn)三、實(shí)驗(yàn)內(nèi)容與步驟1、定義相關(guān)數(shù)據(jù)#define InitPysiBlocks 4#define MaxPages 16:unsigned int PysicalBlocksInitPysiBlocks = 0 ;unsigned int PageSequence30 = 1,2,3,6,4,7,3,2,1,4,7,5,6,5,2,1;2、按照教材中FIFO、LRU算法描述進(jìn)行算法設(shè)計unsigned FIFO(unsigned *py,unsigned *pg)unsigned LRU(unsigned *py,unsigned *pg)3、查看運(yùn)行結(jié)果是否與手

2、工計算一致。四、實(shí)驗(yàn)材料的提交與成績評定1.代碼:#include<iostream>using namespace std;#define InitPysiBlocks 4#define MaxPages 16unsigned int PysicalBlocksInitPysiBlocks = 0 ;unsigned int PageSequence30 = 1,2,3,6,4,7,3,2,1,4,7,5,6,5,2,1 ;/FIFO算法unsigned FIFO(unsigned *py, unsigned *pg)/初始化填滿數(shù)據(jù)for (int i = 0; i <

3、InitPysiBlocks; i+)pyi = pgi;cout << "FIFO置換過程如下:" << endl;cout << py0 << " " << py1 << " " << py2 << " " << py3 << endl;/判斷新獲取數(shù)據(jù)進(jìn)來的時間int time4 = 3,2,1,0 ;/開始檢測for (int i = 4; i < MaxPages; i+)for

4、(int j = 0; j < InitPysiBlocks; j+)/如果新獲取的已存在,直接輸出if (py0 = pgi | py1 = pgi | py2 = pgi | py3 = pgi)cout << py0 << " " << py1 << " " << py2 << " " << py3 << endl;break;elsefor (int k = 0; k < 4; k+)if (timek = 3)time

5、k = 0;pyk = pgi;elsetimek+;cout << py0 << " " << py1 << " " << py2 << " " << py3 << endl;break;cout << "置換結(jié)束" << endl;return 0;/LRU算法/LRU輔助函數(shù):返回除某一排下標(biāo)后數(shù)組中最大元素下標(biāo)int Max(unsigned *py, int te)int max = 0

6、;int index = -1;for (int i = 0; i < InitPysiBlocks; i+)if (i = te)continue;elseif (pyi > max)max = pyi;index = i;elsecontinue;return index;unsigned LRU(unsigned *py, unsigned *pg)/初始化填滿數(shù)據(jù)for (int i = 0; i < InitPysiBlocks; i+)pyi = pgi;cout << "LRU置換過程如下:" << endl;cout

7、 << py0 << " " << py1 << " " << py2 << " " << py3 << endl;/判斷新獲取數(shù)據(jù)進(jìn)來的時間unsigned time4 = 3,2,1,0 ;/統(tǒng)計命中次數(shù)int count4 = 0 ;/開始檢測for (int i = InitPysiBlocks; i < 16; i+)for (int j = 0; j < InitPysiBlocks; j+)/如果新獲取的已存在,直

8、接輸出,并將對應(yīng)的命中變?yōu)?if (py0 = pgi | py1 = pgi | py2 = pgi | py3 = pgi)cout << py0 << " " << py1 << " " << py2 << " " << py3 << endl;if (py0 = pgi)count0 = 1;else if (py1 = pgi)count1 = 1;else if (py2 = pgi)count2 = 1;else if (py

9、3 = pgi)count3 = 1;elsecount4 = 0 ;break;elseif (count0 = 1)/返回數(shù)組中最大值int temp = Max(time, 0);pytemp = pgi;for (int k = 0; k < InitPysiBlocks; k+)timek+;timetemp = 0;count0 = 0;else if (count1 = 1)/返回數(shù)組中最大值int temp = Max(time, 1);pytemp = pgi;for (int k = 0; k < InitPysiBlocks; k+)timek+;timete

10、mp = 0;count1 = 0;else if (count2 = 1)/返回數(shù)組中最大值int temp = Max(time, 2);pytemp = pgi;for (int k = 0; k < InitPysiBlocks; k+)timek+;timetemp = 0;count2 = 0;else if (count3 = 1)/返回數(shù)組中最大值int temp = Max(time, 3);pytemp = pgi;for (int k = 0; k < InitPysiBlocks; k+)timek+;timetemp = 0;count3 = 0;else/返回數(shù)組中最大值int temp = Max(time, -1);pytemp = pgi;for (int k = 0; k < InitPysiBlocks; k+)timek+;timetemp = 0;cout << py0 << " " << py1 << " " << py2 << " " << py3 << en

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論