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


Python Memory.allocate方法代码示例

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


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

示例1: CPU

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import allocate [as 别名]

#.........这里部分代码省略.........
        process.setInCPUTime(simulator.time)
        if self.queueType == "RR" :
            simulator.schedule(simulator.time + burst_time, self.eCPUBurst, process, simulator) 
            if burst_time > self.t_slice:
                simulator.schedule(simulator.time + self.t_slice, self.eRRPreempt, process, simulator) 
        else:
            simulator.schedule(simulator.time + burst_time, self.eCPUBurst, process, simulator) 

        self.contentSwitchSum += 1

    def eCPUBurst(self, process, simulator):
        self.burstTimeSum += process.setOutCPUTime(simulator.time)
	process.currentAgingSeq = random.getrandbits(128)

        process.num_burst -= 1 
        if process.num_burst > 0:
            #time 181ms: P1 completed its CPU burst
            print "time %dms:" % simulator.time,"Process '%c'"%process.letter, "completed its CPU burst [Q",
            sys.stdout.write('')
            self.printQueue()
            print "]"
            #time 181ms: P1 performing I/O
            print "time %dms:"% simulator.time,"Process '%c'"%process.letter, "performing I/O [Q",
            sys.stdout.write('')
            self.printQueue()
            print "]"
            simulator.schedule(simulator.time + process.io_time, self.eIOBurst, process, simulator) 
        else:
            print "time %dms:"% simulator.time,"Process '%c'"%process.letter, "terminated [Q",
            sys.stdout.write('')
            self.printQueue()
            print "]"

            self.mem.deallocate( process.letter )
            print "time %dms:"% simulator.time, "Simulated Memory:"
            self.mem.printmem()

            self.turnaroundTimeSum += simulator.time
            self.active_n -= 1
            if(self.active_n == 0):
                print "time %dms: Simulator for %s ended [Q]" %( simulator.time, self.queueType)
        self.processInCPU = None #Note: process in cpu is in use of CPU, NOT in content switch
        if(not self.process_queue.isEmpty()):
            next_burst_time, next_process = self.process_queue.nextProcess() 
            tmp =next_process.setOutQueueTime(simulator.time)
	    self.waitTimeSum += tmp 
	    self.waitTimeNum += 1 

            simulator.schedule(simulator.time + self.t_cs, self.eContentSwitch, next_process, next_burst_time, simulator) 
            self.CPUIdle = False
        else: #empty process queue
            self.CPUIdle = True
 
    def eIOBurst(self, process, simulator):
        if process.num_burst == 0:
            return

        process.resetRemainBurstTime()

        if self.processInCPU and self.queueType=="SRT" and self.processInCPU.remain_burst_time - (simulator.time - self.processInCPU.lastTimeInCPU) > process.burst_time : 
	# Preempted by SRT
            self.SRTPreempt(process, simulator)
	elif self.processInCPU and self.queueType=="PWA" and self.processInCPU.priority > process.priority:
	# Preempted by PWA
	    process.currentAgingSeq = random.getrandbits(128)
	    self.processInCPU.currentAgingSeq = random.getrandbits(128)
开发者ID:xil12008,项目名称:operatingsystemproject,代码行数:70,代码来源:CPU.py

示例2: printStatusMessage

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import allocate [as 别名]
        iosys.cpu = cpu
        cpu.algorithm = algorithm
        cpu.mem_algorithm = mem_algorithm

        #Start the simulation.
        currentTime = 0
        print "time 0ms: Simulator started for "+cpu.algorithm.upper() +\
            (" (t_slice {0})".format(t_slice) if algorithm == "rr" else "")  +" and "+mem_algorithms[mem_algorithm]


        #Consider the processes in order, only after we added them to the queues. So we don't mess up fcfs.
        processes = copy.deepcopy(origprocesses)
        for process in processes:
            if (process.starttime == 0):
                process.status = "waiting"
                if (not mem.allocate(process.id, process.memsize)):
                    printStatusMessage("Process '{0}' unable to be added; lack of memory".format(process.id))
                    printStatusMessage("Starting defragmentation (suspending all processes)", cpu.processQueue)
                    print "time "+str(currentTime)+"ms: Simulated Memory:\n"+str(mem)
                    #printStatusMessage("Simulated Memory:\n"+str(mem))
                    cpu.memCooldown, cpu.units_defragged = mem.defragment()
                    cpu.status = "defragging"
                    assert(0) #This probably shouldn't happen before we actualy run items.
                
                else:
                    cpu.processQueue.append(process) #Append instead of cpu.addProcessToQueue to avoid unnecessary preemption at time 0.
                    printStatusMessage("Process '{0}' added to system".format(process.id), cpu.processQueue)
                    printStatusMessage("Simulated Memory:\n"+str(mem))

        #Initial sort.
        if (algorithm == "srt"):
开发者ID:not-inept,项目名称:opsys-p3-cpu-sim,代码行数:33,代码来源:BananaComquatPeachApplePinenut.py


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