作業系統 記憶體管理 最佳適應演算法

2021-10-11 02:16:55 字數 3163 閱讀 6988

#include

#include

#include

#include

#include

using

namespace std;

struct node

;node *p,

*s[15];

int piece;

//記錄當前系統中有幾塊空閒區

void

priority_sort

(node *s,

int size)

;void

display

(node *s,

int size)

;void

init_s

(node *p)

temp = temp-

>next;}/

* temp = p;

cout<<

"鍊錶"

(temp !=

null)

cout<<

"s陣列"

int i=

0;i/ cout<<

"更新s陣列後空閒區塊數:"

<}node *

init

(node *p)

first-

>next =

null

; cout<<

"當前系統中有"

<"塊空閒區"

priority_sort

(s,piece)

; cout<<

"按照剩餘空間公升序排列後"

(s,piece)

;return p;

}void

display

(node *ss,

int size)

void

priority_sort

(node *s,

int size)

void

findminnode

(node *ss,

int size,

char

*str)

*/for

(int i=

0;i(ss[i]

->free_space > len)

tail-

>next = ss[i]

->next;

ss[i]

->next = tail;

ss[i]

->str = str;

//cout<<"ss[i]->str "->free_space =0;

ss[i]

->status =1;

flag =

true

; size++

;break;}

}/*cout<<"插入後鍊錶狀態"} */

if(flag)

else

cout<<

"沒有空閒區能裝入字串:"

(p);

/* cout<<"s陣列"(ss,piece);}

void

del(node *pp,

int index)

int len =

strlen

(mid-

>str)

; node *temp1 = p;

/* cout<<"釋放前鍊錶狀態"if(top != null)

cout<<"top找到了"(top !=

null

&& tail !=

null)}

//如果下一塊沒有被使用和下一塊合併

else

if(top-

>status ==0)

}//如果上一塊沒有被使用和上一塊合併

else

if(tail-

>status ==0)

}//如果上下都被使用則插入到對位

else

temp1-

>next = mid;

mid-

>index = temp1-

>index+1;

mid-

>next =

null

; mid-

>free_space = len;

mid-

>status =0;

}}//如果被釋放的是鍊錶中最後一塊

else

if(top !=

null)}

else

temp1-

>next = mid;

mid-

>index = temp1-

>index+1;

mid-

>next =

null

; mid-

>free_space = len;}}

//如果被釋放的是鍊錶中第一塊

else

if(tail !=

null)}

else

temp1-

>next = mid;

mid-

>index = temp1-

>index+1;

mid-

>next =

null

; mid-

>free_space = len;}}

cout<<

"釋放後鍊錶狀態"

while

(temp1 !=

null

)init_s

(p);

priority_sort

(s,piece);}

intmain()

while(1

) temp1 = temp1-

>next;

}display

(s,piece);if

(flag)

cout<<

"找到了,釋放了該資料"

cout<<

"沒找到"

;}return0;

}

作業系統適應演算法

分割槽分配演算法 1 首次適應演算法 first fit 從空閒分割槽表的第乙個表目起查詢該錶,把最先能夠滿足要求的空閒區分配給 作業,這種方法的目的在於減少查詢時間。為適應這種演算法,空閒分割槽表 空閒區鏈 中的空閒分割槽要按位址由低到 高進行排序。該演算法優先使用低址部分空閒區,在低址空間造成許...

作業系統記憶體管理

作業系統記憶體管理 一 程序的虛擬位址空間 每個程序都被賦予自己的虛擬位址空間,對於32位程序來說,這個位址空間為4g,因此程序中的位址可以為0x00000000至0xffffffff之間的任何乙個值。其中4g空間中的低區的2g空間留給程序使用,而高區的2g空間則留給系統使用。在windows200...

作業系統記憶體管理

作業系統記憶體管理一 程序的虛擬位址空間 每個程序都被賦予自己的虛擬位址空間,對於 32位程序來說,這個位址空間為 4g,因此程序中的位址可以為 0x00000000 至0xffffffff 之間的任何乙個值。其中 4g空間中的低區的 2g空間留給程序使用,而高區的 2g空間則留給系統使用。在win...