操作系统:内存分配

时间:2016-04-14 14:39:26

标签: memory memory-management memory-leaks operating-system allocation

问题图片: enter image description here

鉴于上述问题,我有几个问题。首先,proc0代替了一个比它更大的洞,剩下的空间会发生什么?

例如在Q1 i中:引入Proc0之后它是a. 10->15->15->25->30。让15替换20,theres 5离开,那么它会发生什么,我将如何描述它发生了什么?它会是一个。 10-> 5-> 15-> 15-> 25-> 30或a。 10→15-> 5→15-> 25-> 30

1 个答案:

答案 0 :(得分:1)

给定,proc

的大小

sz(proc 0) - > 15 sz(proc 1) - > 5

根据我的理解,Free List (10 -> 20 -> 15 -> 25 -> 30)的变化描述如下:

  

Q1:First Fit(自由列表的大小将开始减少)

When proc 0 (size=15) is brought to the list, 
Free List converts to (10 -> 5 -> 15 -> 25 -> 30)
// the freelist size would decrease wherever the first biggest hole is found,
// so, hole of size 20 is replaced by a hole of size 5 to allocate memory to proc 0

When proc 1 (size=5) is brought to the list, 
Free List converts to (5 -> 5 -> 15 -> 25 -> 30)
// the freelist size would decrease wherever the first biggest hole is found,
// so, hole of size 10 is replaced by a hole of size 5 to allocate memory to proc 1

假设在执行First Fit分配之前FreeList再次相同(10 -> 20 -> 15 -> 25 -> 30)

  

Q2:Next Fit(自由列表的大小将开始减少)

When proc 0 (size=15) is brought to the list, 
Free List converts to (10 -> 5 -> 15 -> 25 -> 30)
// the freelist size would decrease wherever the next biggest hole is found,
// so, hole of size 20 is replaced by a hole of size 5 to allocate memory to proc 0

When proc 1 (size=5) is brought to the list, 
Free List converts to (10 -> 0 -> 15 -> 25 -> 30), or better
Free List converts to (10 -> 15 -> 25 -> 30)    // the size of the freelist decreases.
// the freelist size would decrease wherever the next biggest hole is found,
// so, hole of size 5 is replaced by a hole of size 0
// (or, rather no hole left, so list becomes continuous) to allocate memory to proc 1