def mergeHoles(self): i = 0 while len(self.__listOfAllPartitions) > 1: if self.__listOfAllPartitions[i].getName() == 'Hole': while self.__listOfAllPartitions[i + 1].getName() == 'Hole': start = self.__listOfAllPartitions[i].getStartingAddress() end = self.__listOfAllPartitions[i + 1].getEndingAddress() size = self.__listOfAllPartitions[i].getSize( ) + self.__listOfAllPartitions[i + 1].getSize() newHole = partition('Hole', 'none', -1, 'Hole', start, size, end) secondStart = self.__listOfAllPartitions[ i + 1].getStartingAddress() self.removeSegment(start, self.__listOfAllPartitions) self.removeSegment(start, self.__listOfHoles) self.removeSegment(secondStart, self.__listOfAllPartitions) self.removeSegment(secondStart, self.__listOfHoles) self.__listOfHoles.append(newHole) self.__listOfAllPartitions.append(newHole) self.__listOfAllPartitions.sort( key=operator.attrgetter('_partition__startAddress')) a = i + 1 if a == len(self.__listOfAllPartitions): break i += 1 if i >= (len(self.__listOfAllPartitions)) - 1: break
def addSegment(self, name, size): currentProc = self.__listOfAllProcesses[-1] newName = self.__listOfAllProcesses[-1].getName() + ' ' + name newSeg = partition(newName, currentProc.getName(), currentProc.getNoOfAddedSegments(), 'segment', -1, size, -1) currentProc.getListOfSegments().append(newSeg) noOfAddedSeg = currentProc.getNoOfAddedSegments() currentProc.setNoOfAddedSegments(noOfAddedSeg + 1)
def quicksort(array, start, end): if (start < end): # print(array,start,"Hello") array, index = partition(array, start, end) array = quicksort(array, start, index) array = quicksort(array, index + 1, end) return array
from tkinter import * from Partition import partition from MemoryManager import memoryManager from DisplayMem import displayMem from Process import process from Table import table x=Tk() list_segments=[] for i in range(10): a=partition() a.setName("seg"+str(i)) a.setSize(i+1) list_segments.append(a) for i in range(len(list_segments)): if i==0: list_segments[i].setStartingAddress(0) list_segments[i].setEndingAddress( list_segments[i].getStartingAddress()+list_segments[i].getSize()) else: list_segments[i].setStartingAddress(list_segments[i-1].getEndingAddress()) list_segments[i].setEndingAddress( list_segments[i].getStartingAddress() + list_segments[i].getSize()) mem_display=displayMem() mem_display.drawMem(x,list_segments) table=table() table.drawTable(list_segments) x.mainloop()
def displayOldProcess(self, startingAddress, size): name = 'Old Process' + ' ' + str(self.__oldProcessesNo) newSeg = partition(name, name, len(self.__listOfHoles), 'Old Process', startingAddress, size, startingAddress + size) self.__listOfAllPartitions.append(newSeg) self.__oldProcessesNo += 1
def addHole(self, startingAddress, size): newSeg = partition('Hole', 'none', len(self.__listOfHoles), 'Hole', startingAddress, size, startingAddress + size) self.__listOfHoles.append(newSeg)