91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

計算機操作系統的動態分區分配與回收實驗的Python實現代碼。

資源截圖

代碼片段和文件信息

from?random?import?randint

class?storage(object):
????def?__init__(selfsize):
????????self.memory_size?=?size

#首次適應算法
class?OS_1(object):
????storageUnit?=?storage(12)
????temp?=?storageUnit.memory_size
????memory_list?=?[0?for?i?in?range(temp)]??#物理存儲單元,初始化為0
????memory_addr?=?[0?for?i?in?range(temp)]?#記錄每個單元是否使用初始化為0
????memory_block?=?[]

????#分配內存部分
????def?allocate_unit(selfneed_size):
????????size_count?=?0
????????record?=?0
????????flag?=?True
????????memory_list?=?[]
????????for?addr?in?range(self.storageUnit.memory_size):
????????????if?self.memory_addr[addr]?==?0:
????????????????if?flag:
????????????????????record?=?addr?#記錄開始地址來便儲存某物
????????????????????flag?=?False
????????????????size_count?+=?1
????????????????if?size_count?==?need_size:#當前存儲塊滿足所需大小時,進行存儲
????????????????????for?i?in?range(size_count):
????????????????????????self.memory_list[size_count+i]?=?chr(1111)
????????????????????????self.memory_addr[record+i]?=?1?#標記
????????????????????????memory_list.append(record+i)?#塊內空間
????????????????????self.memory_block.append(memory_list)#記錄塊
????????????????????break
????????????else:#不滿足時,重新尋找新的內存塊,last_count重置為0
????????????????size_count?=?0
????????????????flag?=?True
????????if?size_count?????????????print(‘!!分配內存失敗!!沒有足夠內存分配給該作業!‘)

????#回收部分
????def?reclaim_unit(selfidentifier):
????????if?identifier?>?len(self.memory_block):
????????????print(‘error?input‘)
????????????exit(1)
????????for?addr?in?self.memory_block[identifier]:
????????????self.memory_addr[addr]?=?0
????????self.memory_block.remove(self.memory_block[identifier])

????#存儲顯示部分
????def?memoryView(self):
????????print(‘當前的內存存儲情況為:‘)
????????for?count?in?range(len(self.memory_block)):
????????????start?=?self.memory_block[count][0]
????????????end?=?self.memory_block[count][len(self.memory_block[count])-1]
????????????lenth?=?len(self.memory_block[count])
????????????print(‘分區:‘count‘\t‘‘大小:‘lenth‘\t‘‘地址:‘start‘~‘end)

#循環首次適應算法
class?OS_2(object):
????storageUnit?=?storage(12)
????temp?=?storageUnit.memory_size
????memory_list?=?[0?for?i?in?range(temp)]??#物理存儲單元,初始化為0
????memory_addr?=?[0?for?i?in?range(temp)]?#記錄每個單元是否使用初始化為0
????memory_block?=?[]
????memory?=?0#標記上次分配地址塊的位置

????def?allocate_unit(selfneed_size):
????????size_count?=?0
????????record?=?0
????????flag?=?True
????????memory_list?=?[]
????????for?addr?in?range(self.storageUnit.memory_size):
????????????location?=?(self.memory?+?addr)?%?self.storageUnit.memory_size
????????????if?self.memory_addr[location]?==?0:
????????????????if?flag:
????????????????????record?=?location?#記錄開始地址來便儲存某物
?????????????

評論

共有 條評論