《計算機操作系統(tǒng)頁面置換源碼》由會員分享,可在線閱讀,更多相關(guān)《計算機操作系統(tǒng)頁面置換源碼(4頁珍藏版)》請在裝配圖網(wǎng)上搜索。
1、v1.0可編輯可修改#include #include #include using namespacestd;#define MEM_SIZE 32#define RAM SIZE 16#define SWAP SIZE 32 static char ramRAM SIZE; static char SwapSWAP SIZE map M;struct page item ata = i;end_list = &itemi;resent) struct test_item * prev = first_list;struct test item * cur = first list-next
2、; while (cur != NULL)if (cur-data = laddr)prev-next = cur-next;cur-next = NULL;end_list-next = cur;end_list = cur;break;prev = cur;cur = cur-next;return page_tableladdr.ram_addr;odified) am_addr;Swappage_tablepage.swap_addr = data;page_tablepage.present = falseam_addr;page_tableladdr.ram_addr = padd
3、r;rampaddr = Swappage_tableladdr.swap_addr;page_tableladdr.modified = falsepage_tableladdr.present = true;page_tableladdr.access = 1;return paddr;int mem read(int addr, char *buf)if (addr MEM_SIZE)return -1;int paddr = mem access(addr);*buf = rampaddr;odified = true ;return 0;void mem_init( void )4w
4、ap_addr = i;page_tablei.present = false page_tablei.modified = falseam_addr = i;page_tablei.present = true;page_tablei.access = 0;void mem_state( void )printf( ram state:t );for ( int i = 0; i RAM_SIZE; i+) printf( %d , rami);printf( nswap state:t );for (int i = 0; i next;printf( access record: n );
5、while (cur != NULL)printf( %d , cur-data);prev = cur;cur = cur-next;void mem_test( void )printf(031為地址,在其中依次寫入031,則前16個將會被置換n);int test10 = 1,3, 5, 9, 6, 7, 19, 18, 31,0 ;for (int i = 0; i 32; i+)mem_write(i, i);mem_state();history_show();printf( n訪問22號單元,22f鏈表末段n );mem_write(22, 22);history_show();printf( n 訪問 11 單元,11 f鏈表末段,16-replace:n );mem_write(11, 11);history_show();int main( int argc, const char *argv口)mem_init();init_test_list();mem_test();system( pause);return 0;