計算機操作系統(tǒng)頁面置換源碼
v1.0可編輯可修改#include <>#include <iostream>#include <map> using namespacestd;#define MEM_SIZE 32#define RAM SIZE 16#define SWAP SIZE 32 static char ramRAM SIZE; static char SwapSWAP SIZE map<nt , int > M;struct page item ata = i;end_list = &itemi;resent) struct test_item * prev = first_list;struct test item * cur = first list->next; 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 = paddr;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 < 0 | addr > MEM_SIZE)return -1;int paddr = mem access(addr);*buf = rampaddr;odified = true ;return 0;void mem_init( void )4wap_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 < SWAP_SIZE; i+) printf( "%d ", Swapi);printf( "nn");void history_show() /顯示訪問記錄表struct test_item * prev = first_list;struct test_item * cur = first_list->next;printf( "access record: n ");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;