void findSpans(vector <string> &memoryTable,vector <Spans*> &spanVector) { resetSpanVector(spanVector); int sizeofTable = memoryTable.size(); int beginning = -1; int ending = -1; bool Bfound = false; bool Efound = false; bool allFree = true; for(int i = 0; i < sizeofTable; i++) { if(i == sizeofTable-1 && allFree == true) { ending = sizeofTable; Spans *newSpan = new Spans(beginning,ending,true); newSpan->setName("free"); spanVector.push_back(newSpan); Bfound = false; Efound = false; } else if(memoryTable[i] == "free" && Bfound == false) { beginning = i; Bfound = true; } else if(memoryTable[i] != "free" && Efound == false) { allFree = false; ending = i-1; Spans *newSpan = new Spans(beginning,ending,false); newSpan->setName("free"); spanVector.push_back(newSpan); Bfound = false; Efound = false; } } cout << "size: " << spanVector.size() << endl; /* Spans* current = NULL; for(int x = 0; x < signed(spanVector.size());x++) { current = spanVector[x]; cout << current->getName() << "\tBeginning: " << current->getBeginning() << " Ending: " << current->getEnding() << endl; }*/ Sleep(3000); }
bool firstFit(PCBStruct *newProcess,vector <string> &memoryTable,vector <Spans*> &spanVector) { int spacesNeeded = newProcess->getMemoryNeeded(); int sizeOfTable = memoryTable.size(); int sizeOfVector = spanVector.size(); int difference = 0; int range = 0; int counter = 0; Spans* currentSpan = NULL; for(int a = 0; a < sizeOfVector; a++) { currentSpan = spanVector[a]; difference = currentSpan->getEnding() - currentSpan->getBeginning() + 1; range = currentSpan->getBeginning() + spacesNeeded; // cout << "needed: " << spacesNeeded << "\tdifference: " << difference << endl; if(difference >= spacesNeeded) { counter = currentSpan->getBeginning(); currentSpan->setName(newProcess->getProcessName()); cout << "255" << endl; for(int i = currentSpan->getBeginning(); i < range; i++) { memoryTable[i] = newProcess->getProcessName(); } return true; } else { return false; } } //cout << "259" << endl << endl << endl; // showMemoryTable(newProcess,memoryTable,spanVector); }