現在、私は、リンクされたリストデータ構造の同意を使用してオペレーティングシステムのメモリ管理シミュレーションプログラムを開発しています。コードを実行すると、パーツインタプリタは、非タイプの属性エラーがあると言います。それは私を混乱させます。それは私のコード内のすべての部分の私のishole
属性を除いて動作します。誰にでもエラーを教えてもらえますか?リンクを使用したメモリ管理システムの実装
class Node:
def __init__(self,size,hole_or_not,s_index,e_index,psid):
self.block_size=size
self.ishole=hole_or_not
self.stat_index=s_index
self.end_index=e_index
self.ps_id=psid
self.next=None
class MemoryManagement:
def __init__(self,os_size=400,totalsize=2560):
self.head=Node(os_size,False,0,os_size-1,'os')
self.head.next=Node(totalsize-os_size,True,os_size,totalsize,'free')
self.totalfreespace=totalsize-os_size
self.os_allocated=os_size
def allocate(self,pid,size):
current=self.head
while current.ishole!=False or current.block_size<size:
if current.ishole and current.block_size==size:
current.ps_id=pid
current.ishole=False
elif current.ishole and current.block_size>size:
hold_start_memory_address=current.stat_index
hold_end_memory_address=current.end_index
hold_block_size_current=current.block_size
current.ps_id=pid
current.block_size=size
current.end_index=hold_start_memory_address+size-1
current.ishole=False
remain=Node(hold_block_size_current-size,True,hold_start_memory_address+size,hold_end_memory_address-1,'free')
remain.next=current.next
current.next=remain
current=current.next
else:
print('----')
def printstack(self):
current=self.head
while current.next:
print(current.ps_id,current.block_size,current.stat_index,current.end_index,current.ishole)
current=current.next
は、その後、私は
o=MemoryManagement()
o.allocate('p1',100)
o.allocate('p2',500)
o.allocate('p3',1200)
o.allocate('p4',1000)
o.printstack()
お気に入りのテストケースを使用しそれから私はこのようなエラーが発生しましたが、私は理由を理解することはできません。それだけで
while current.ishole!=False or current.block_size<size:
AttributeError: 'NoneType' object has no attribute 'ishole'
[Finished in 0.13s]
ありがとう –