当前位置: 首页>>代码示例>>Python>>正文


Python Memory.put方法代码示例

本文整理汇总了Python中memory.Memory.put方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.put方法的具体用法?Python Memory.put怎么用?Python Memory.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在memory.Memory的用法示例。


在下文中一共展示了Memory.put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import put [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
开发者ID:DavidCorrea,项目名称:UNQ-SO-2014,代码行数:39,代码来源:MemoryManager.py

示例2: MemoryTest

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import put [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)
开发者ID:DavidCorrea,项目名称:UNQ-SO-2014,代码行数:34,代码来源:MemoryTest.py


注:本文中的memory.Memory.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。