void compareSpacesNeededToSpan(PCBStruct *newProcess,vector <string> &memoryTable,vector <Spans*> &spanVector) { int spacesNeeded = newProcess->getMemoryNeeded(); int spacesDifference = 0; int spacesInSpan = 0; vector<int> spacesDifferenceVector; Spans* current = NULL; for(int i = 0; i < spanVector.size();i++) { current = spanVector[i]; spacesInSpan = current->getEnding() - current->getBeginning() + 1; if(spacesInSpan > spacesNeeded) { spacesDifference = spacesInSpan-spacesNeeded; spacesDifferenceVector.push_back(spacesDifference); } else { spacesDifferenceVector.push_back(-1); } } bestFit(newProcess,memoryTable,spanVector,spacesDifferenceVector); worstFit(newProcess,memoryTable,spanVector,spacesDifferenceVector); }
//adds a PCB to running queue using memory management void pcbQueue::addPCBFit(char whichFit, pcb* nPCB) { switch(whichFit) { case 'F': { bool done = false; done = firstFit(nPCB); if (!done) { coalesce(); done = firstFit(nPCB); } else { return; } if (!done) { compact(); done = firstFit(nPCB); } } break; case 'N': { bool done = false; done = nextFit(nPCB); if (!done) { coalesce(); done = nextFit(nPCB); } if (!done) { compact(); done = nextFit(nPCB); } } break; case 'B': { bool done = false; done = bestFit(nPCB); if (!done) { coalesce(); done = bestFit(nPCB); } if (!done) { compact(); done = bestFit(nPCB); } } break; case 'W': { bool done = false; done = worstFit(nPCB); if (!done) { coalesce(); done = worstFit(nPCB); } if (!done) { compact(); done = worstFit(nPCB); } } break; default: { bool done = false; done = firstFit(nPCB); if (!done) { coalesce(); done = firstFit(nPCB); } if (!done) { compact(); done = firstFit(nPCB); } } } queueSize = heldItems.size(); }