《計(jì)算機(jī)操作系統(tǒng)頁(yè)面置換源碼》由會(huì)員分享,可在線閱讀,更多相關(guān)《計(jì)算機(jī)操作系統(tǒng)頁(yè)面置換源碼(4頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。
1、v1.0可編輯可修改
#include <>
#include
#include
2、* 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_table[laddr].ram_addr;
}
odified) { am_ad
3、dr];
Swap[page_table[page].swap_addr] = data;
page_table[page].present = false
am_addr;
page_table[laddr].ram_addr = paddr;
ram[paddr] = Swap[page_table[laddr].swap_addr];
page_table[laddr].modified = false
page_table[laddr].present = true;
page_table[laddr].access = 1;
return paddr;
int m
4、em read(int addr, char *buf)
if (addr < 0 || addr > MEM_SIZE)
return -1;
int paddr = mem access(addr);
*buf = ram[paddr];
odified = true ;
return 0;
}
void mem_init( void )
{
4
wap_addr = i;
page_table[i].present = false page_table[i].modified = false
am_addr = i;
page_table[i].prese
5、nt = true;
page_table[i].access = 0;
void mem_state( void )
printf( "ram state:\t" );
for ( int i = 0; i < RAM_SIZE; i++) {
printf( "%d ", ram[i]);
printf( "\nswap state:\t" );
for (int i = 0; i < SWAP_SIZE; i++) {
printf( "%d ", Swap[i]);
printf( "\n\n");
void history_show(){ //顯示訪問(wèn)記錄表
s
6、truct 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( "0?31為地址,在其中依次寫入0?31,則前16個(gè)將會(huì)被置換\n");
int test[10] = {1,3, 5, 9, 6, 7
7、, 19, 18, 31,0 };
for (int i = 0; i < 32; i++){
mem_write(i, i);
mem_state();
history_show();
printf( "\n訪問(wèn)22號(hào)單元,22f鏈表末段\n ");
mem_write(22, 22);
history_show();
printf( "\n 訪問(wè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;