




已閱讀5頁,還剩13頁未讀, 繼續免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
實 驗 報 告(2014 / 2015 學年 第 一 學期)課程名稱計算機操作系統實驗名稱虛擬存儲中頁面置換算法的模擬實現實驗時間2014年12月19日指導單位南京郵電大學指導教師崔衍學生姓名班級學號學院(系)物聯網院專 業網絡工程實 驗 報 告實驗名稱虛擬存儲中頁面置換算法的模擬實現指導教師崔衍實驗類型上機實驗實驗學時4實驗時間2014.12.19一、 實驗目的和要求目的:通過請求頁式存儲管理中頁面置換算法模擬設計,了解虛擬存儲技術的技術特點,掌握請求頁式存儲管理的頁面置換算法要求:(1)設計實現下面算法,并輸出下述各種算法的命中率。 先進先出的算法(FIFO); 最近最少使用算法(LRR); 最佳淘汰算法(OPT)先淘汰最不常用的頁地址。(2)多次反復運行改進后的程序,觀察并記錄運行結果,并分析原因。二、實驗環境(實驗設備)Vc+6.0二、 實驗原理及內容實驗三#include #include#include#include#define Bsize 4typedef struct BLOCK/聲明一種新類型物理塊類型 int pagenum;/頁號 int accessed;/訪問字段,其值表示多久未被訪問BLOCK; int pc;/程序計數器,用來記錄指令的序號int n;/缺頁計數器,用來記錄缺頁的次數 static int temp320;/用來存儲320條隨機數BLOCK blockBsize; /定義一大小為4的物理塊數組/*void init( ); /程序初始化函數int findExist(int curpage);/查找物理塊中是否有該頁面int findSpace( );/查找是否有空閑物理塊int findReplace( );/查找應予置換的頁面void display ( );/顯示void suijishu( );/產生320條隨機數,顯示并存儲到temp320void pagestring( );/顯示調用的頁面隊列void OPT( );/OPT算法void LRU( );/ LRU算法void FIFO( );/FIFO算法/*void init( ) for(int i=0;iBsize;i+) blocki.pagenum=-1; blocki.accessed=0; pc=n=0; /-int findExist(int curpage) for(int i=0; iBsize; i+) if(blocki.pagenum = curpage ) return i;/檢測到內存中有該頁面,返回block中的位置 return -1;/-int findSpace( ) for(int i=0; iBsize; i+) if(blocki.pagenum = -1) return i;/找到空閑的block,返回block中的位置 return -1;/-int findReplace( ) int pos = 0; for(int i=0; iblockpos.accessed) pos = i;/找到應予置換頁面,返回BLOCK中位置 return pos;/-void display( ) for(int i=0; iBsize; i+) if(blocki.pagenum != -1) printf( %02d,blocki.pagenum); coutpc; cout*按照要求產生的320個隨機數:*endl; for(int i=0;i320;i+) tempi=pc; if(flag%2=0) pc=+pc%320; if(flag=1) pc=rand( )% (pc-1); if(flag=3) pc=pc+1+(rand( )%(320-(pc+1); flag=+flag%4; printf( %03d,tempi); if(i+1)%10=0) coutendl; /-void pagestring( ) for(int i=0;i320;i+) printf( %02d,tempi/10); if(i+1)%10=0) coutendl; /-void OPT( ) int exist,space,position ; int curpage; for(int i=0;i320;i+) if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace ( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else for(int k=0;kBsize;k+) for(int j=i;j320;j+) if(blockk.pagenum!= tempj/10) blockk.accessed = 1000; /將來不會用,設置為一個很大數 else blockk.accessed = j; break; position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; cout缺頁次數:nendl; cout缺頁率:(n/320.0)*100%endl;/- void LRU( ) int exist,space,position ; int curpage; for(int i=0;i320;i+) if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; else blockexist.accessed = -1;/恢復存在的并剛訪問過的BLOCK中頁面accessed為-1 for(int j=0; j4; j+) blockj.accessed+; cout缺頁次數:nendl; cout缺頁率:(n/320.0)*100%endl;/-void FIFO( ) int exist,space,position ; int curpage; for(int i=0;i320;i+) if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; blockposition.accessed-; for(int j=0; jBsize; j+) blockj.accessed+; cout缺頁次數:nendl; cout缺頁率:(n/320.0)*100%endl;/*void main( ) int select; cout請輸入第一條指令號(0320):; suijishu( ); cout*對應的調用頁面隊列*endl; pagestring( ); do cout*endl; cout-1:OPT 2:LRU 3:FIFO 4:退出-endl; cout*endl; coutselect; cout*endl; init( ); switch(select) case 1:cout最佳置換算法OPT:endl; cout*endl; OPT( ); break; case 2:cout最近最久未使用置換算法LRU:endl; cout*endl; LRU( ); break; case 3:cout先進先出置換算法FIFO:endl; cout*endl; FIFO( ); break; default: ; while(select!=4);實驗結果: 實驗四Login用戶登錄bool chklogin(char *users, char *pwd)int i;for(i=0; itemp-filename;cintemp-content;if(recent-child=NULL)temp-parent=recent;temp-child=NULL;recent-child=temp;temp-prev=temp-next=NULL;cout文件建立成功!child;while(ttemp-next)ttemp=ttemp-next;if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=0)printf(對不起,文件已存在!);return 1;ttemp-next=temp;temp-parent=NULL;temp-child=NULL;temp-prev=ttemp;temp-next=NULL;cout文件建立成功!endl;return 1;int dir()int i=0,j=0;temp=new fnode;temp=recent;if(temp!=root)cout .child=NULL)coutTotal: directors i files j child;while(temp)if(temp-isdir)cout filenameendl;i+;elsecout filenamenext;coutTotal: directors ifiles j filename;if(recent-child=NULL)cout文件不存在!child-filename,filename)=0)coutchild-contentchild;while(temp-next)if(strcmp(temp-next-filename,filename)=0)coutnext-contentendl;return 1;cout文件不存在!filename;if(recent-child=NULL)cout文件不存在!child-filename,filename)=0)recent-child-isopen=1;/設置文件標記為打開cinrecent-child-content;recent-child-isopen=0;/設置文件標記為關閉cout文件寫入成功!child;while(temp-next)if(strcmp(temp-next-filename,filename)=0)recent-child-isopen=1;/設置文件標記為打開cintemp-next-content;recent-child-isopen=0;/設置文件標記為關閉cout文件寫入成功!endl;return 1;cout文件不存在!filename;temp=new fnode;if(recent-child)temp=recent-child;while(temp-next & (strcmp(temp-filename,filename)!=0 | temp-isdir!=0)temp=temp-next;if(strcmp(temp-filename,filename)!=0)cout不存在該文件!endl;return 0;elsecout不存在該文件!parent=NULL)temp-prev-next=temp-next;if(temp-next)temp-next-prev=temp-prev;temp-prev=temp-next=NULL;elseif(temp-next)temp-next-parent=temp-parent;temp-parent-child=temp-next;delete temp;cout文件已刪除!temp-filename;if(recent-child=NULL)temp-parent=recent;temp-child=NULL;recent-child=temp;temp-prev=temp-next=NULL;elsettemp=recent-child;while(ttemp-next)ttemp=ttemp-next;if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=1)printf(對不起,目錄已存在!);return 1;ttemp-next=temp;temp-parent=NULL;temp-child=NULL;temp-prev=ttemp;temp-next=NULL;return 1;切換目錄int dir()int i=0,j=0;temp=new fnode;temp=recent;if(temp!=root)cout .child=NULL)coutTotal: directors i files j child;while(temp)if(temp-isdir)cout filenameendl;i+;elsecout filenamenext;coutTotal: directors ifiles j endl;四、實驗小結(包括問題和解決方法、心得體會、意見與建議等) 通過課程設
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 西安航空學院《建設工程監理》2023-2024學年第二學期期末試卷
- 伐木機械智能化維護與管理系統創新創業項目商業計劃書
- 圖書出版發行AI應用企業制定與實施新質生產力項目商業計劃書
- 麻辣香鍋自助店企業制定與實施新質生產力項目商業計劃書
- 醫藥創新孵化器行業跨境出海項目商業計劃書
- 瀟湘職業學院《工程項目經濟原理》2023-2024學年第二學期期末試卷
- 信息傳輸在線平臺行業深度調研及發展項目商業計劃書
- 糖尿病眼病防治藥行業深度調研及發展項目商業計劃書
- 河北政法職業學院《藥理學》2023-2024學年第二學期期末試卷
- 山東工藝美術學院《商務英語視聽說IV》2023-2024學年第二學期期末試卷
- 2025天貓服飾春夏趨勢白皮書
- 2024年冬季N0M世界青少年數學思維研學活動模擬題
- 2024NEA水性氣硅涂膏隔熱保溫墻體構造
- DB61T1536-2022工業鍋爐運行管理規范
- SH/T 3046-2024 石油化工立式圓筒形鋼制焊接儲罐設計規范(正式版)
- JT∕T 795-2023 事故汽車修復技術規范
- 預防接種門診驗收表4-副本
- 外國文學之旅智慧樹知到期末考試答案章節答案2024年山東師范大學
- 駕駛檔案注銷委托書
- 焊接規范的基本要求
- 廣東省廣州市2024屆七年級生物第二學期期末教學質量檢測模擬試題含解析
評論
0/150
提交評論