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


Python Memory.get方法代码示例

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


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

示例1: MemoryTest

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import get [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

示例2: __init__

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import get [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

示例3: __init__

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import get [as 别名]
class MifFile:
    def __init__(self, filename):
        self.filename = filename

    def read(self):
        try:
            with open(self.filename, "r") as f:
                self.__read_header(f)
                self.__read_content(f)
        except IOError:
            pass

    def init(self, size, unit):
        self.memory = Memory(size, unit)

    def __read_header(self, f):
        l = f.readline()
        m = re.match(r"^\s*DEPTH\s*=\s*([0-9]*)\s*;\s*$", l)
        if m == None:
            raise BadMIF()
        depth = int(m.group(1))
        l = f.readline()
        m = re.match(r"^\s*WIDTH\s*=\s*([0-9]*)\s*;\s*$", l)
        if m == None:
            raise BadMIF()
        unit = int(m.group(1))
        if unit % 8 != 0:
            raise BadMIFParameter()
        unit = unit / 8
        l = f.readline()
        m = re.match(r"^\s*ADDRESS_RADIX\s*=\s*HEX\s*;\s*$", l)
        if m == None:
            raise BadMIF()
        l = f.readline()
        m = re.match(r"^\s*DATA_RADIX\s*=\s*HEX\s*;\s*$", l)
        if m == None:
            raise BadMIF()
        self.memory = Memory(depth * unit, unit)

    def __read_content(self, f):
        l = f.readline()
        m = re.match(r"^\s*CONTENT\s*$", l)
        if m == None:
            raise BadMIF()
        l = f.readline()
        m = re.match(r"^\s*BEGIN\s*$", l)
        if m == None:
            raise BadMIF()

        re_end = re.compile(r"^\s*END\s*;\s*$")
        re_content = re.compile(r"^\s*([0-9a-fA-F]+)\s*:\s*([0-9a-fA-F]{%d})\s*;\s*(?:-- (.*))?\s*$" % (self.memory.unit*2))
        l = f.readline()
        while re_end.match(l) == None:
            m = re_content.match(l)
            if m == None:
                raise BadMIF()
            self.memory.set(int(m.group(1),16)*self.memory.unit, map(lambda x: int(x,16), [ m.group(2)[i*2:i*2+2] for i in xrange(0,len(m.group(2))/2) ]), m.group(4))
            l = f.readline()
            if l == "":
                break
        if l == "":
            raise BadMIF()

    def __print_header(self, f):
        print >>f, "DEPTH = %d;" % (self.memory.size / self.memory.unit)
        print >>f, "WIDTH = %d;" % (self.memory.unit * 8)
        print >>f, "ADDRESS_RADIX = HEX;"
        print >>f, "DATA_RADIX = HEX;"

    def __print_content(self, f):
        print >>f, "CONTENT"
        print >>f, "BEGIN"
        for i in xrange(0, self.memory.size, self.memory.unit):
            line = self.memory.get(i)
            if line[1] == None:
                print >>f, "%4X : %s;" % (i / self.memory.unit, reduce(lambda x,y:x+y, map(lambda x:"%02x"%(x), line[0][::-1])))
            else:
                print >>f, "%4X : %s; -- %s" % (i / self.memory.unit, reduce(lambda x,y:x+y, map(lambda x:"%02x"%(x), line[0][::-1])), line[1])
        print >>f, "END;"

    def write_back(self):
        try:
            with open(self.filename, "w") as f:
                self.__print_header(f)
                self.__print_content(f)
        except IOError:
            print >>sys.stderr, "Can't open file for write"
开发者ID:rododo-meow,项目名称:mips-fpga,代码行数:89,代码来源:mifutil.py


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