本文整理汇总了Python中memory.Memory.get_free_space方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.get_free_space方法的具体用法?Python Memory.get_free_space怎么用?Python Memory.get_free_space使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类memory.Memory
的用法示例。
在下文中一共展示了Memory.get_free_space方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MemoryTest
# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import get_free_space [as 别名]
class MemoryTest(unittest.TestCase):
# Arrange
def setUp(self):
self.memory = Memory(20)
self.instruction1 = InstructionCPU()
self.instruction2 = InstructionIO()
self.instruction3 = InstructionCPU()
def test_whenTheMemoryAddsAnInstructionAndIAskForIt_thenIGetIt(self):
self.memory.put(0, self.instruction1)
self.memory.put(1, self.instruction2)
self.memory.put(2, self.instruction3)
self.assertEqual(self.memory.get(0), self.instruction1)
self.assertEqual(self.memory.get(1), self.instruction2)
self.assertEqual(self.memory.get(2), self.instruction3)
def test_whenISetThreeInstructions_thenIGetTwoFreeSpaces(self):
self.memory.put(0, self.instruction1)
self.memory.put(1, self.instruction2)
self.memory.put(2, self.instruction3)
self.assertEqual(self.memory.get_free_space(), 17)
def test_whenIHaveSomeInstructionsAndCompact_thenItAllGoesUp(self):
for index in range(0, 5):
self.memory.put(index, self.instruction1)
for index in range(12, 14):
self.memory.put(index, self.instruction2)
for index in range(17, 20):
self.memory.put(index, self.instruction2)
self.memory.compact()
self.assertEqual(self.memory.get(19), None)
示例2: __init__
# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import get_free_space [as 别名]
class MemoryManager:
def __init__(self, hdd):
self._memory = Memory(2048)
self._next_index = 0
self._policy = None
self._memory_free_space = self._memory.get_free_space()
self._hdd = hdd
def write(self, pcb):
policy_result = self._policy.assign_to_memory(pcb)
aux = policy_result.get_start_index()
instructions = pcb.get_instructions()
for inst in instructions:
self._memory.put(aux, inst)
aux += 1
def read(self, mem_dir):
return self._memory.get(mem_dir)
def can_serve(self,pcb):
return self._memory_free_space >= pcb.get_amount_of_instructions()
def set_as_ca(self, ca_policy):
self._policy = ContinuousAssignment(self._memory, ca_policy)
def set_as_paging(self, instructions_per_frame):
self._policy = Paging(self._memory, instructions_per_frame, self._hdd)
def get_memory(self):
return self._memory
def get_policy(self):
return self._policy
def set_policy(self, policy):
self._policy = policy