Ejemplo n.º 1
0
//joins contigious spans together
void coalescing(vector <Spans*> spansVector)
{
    int firstBeginning = 0;
    int firstEnding = 0;
    int secondBeginning = 0;
    int secondEnding = 0;

    Spans* current = NULL;
    Spans* next = NULL;
    for(int i = 0; i < spansVector.size();i++)
    {
        current = spansVector[i];
        next = spansVector[i+1];
        firstBeginning = current->getBeginning();
        firstEnding = current->getEnding();
        secondBeginning = next->getBeginning();
        secondEnding = next->getEnding();

        if(firstEnding+1 == secondBeginning)
        {
            spansVector[i] = NULL;
            spansVector[i+1] = NULL;

            Spans* newSpan = new Spans(firstBeginning,firstEnding,true);
            newSpan->setBeginning(firstBeginning);
            newSpan->setEnding(secondEnding);

            spansVector[i] = newSpan;
            removeNULLsFromVector(spansVector);
        }
    }

}
Ejemplo n.º 2
0
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);

}
Ejemplo n.º 3
0
void nextFit(PCBStruct *newProcess,vector <string> &memoryTable,vector <Spans*> &spanVector)
{
    findSpans(memoryTable,spanVector);

    int spacesNeeded = newProcess->getMemoryNeeded();
    int difference = 0;
    int range = 0;

    Spans* current = NULL;
    for(int i = 0; i < spanVector.size();i++)
    {
        current = spanVector[i];
        difference = current->getEnding() - current->getBeginning() + 1;
        if(difference >= spacesNeeded)
        {
            range = current->getBeginning() + spacesNeeded;
            for(int x = current->getBeginning(); x <= spacesNeeded; x++)
            {
                memoryTable[x] = newProcess->getProcessName();
            }
        }
    }

    findSpans(memoryTable,spanVector);
}
Ejemplo n.º 4
0
void matchVectors(vector <string> &memoryTable, vector <Spans*> spansVector)
{
    int sizeOfTable = memoryTable.size();
    int sizeOfVector = spansVector.size();
    Spans* current = NULL;

    for(int i = 0; i < sizeOfVector; i++)
    {
        current = spansVector[i];
        for(int x = current->getBeginning(); x <= current->getEnding(); x++)
        {
            memoryTable[x] = current->getName();
        }
    }
}
Ejemplo n.º 5
0
//joins all contiguious spans together at end of table
void condensing(vector <Spans*> spanVector, vector <string> memoryTable)
{
    coalescing(spanVector);
    int totalFreeSpaces = 0;
    int difference = 0;

    Spans* current = NULL;
    for(int i = 0; i < spanVector.size(); i++)
    {
        current = spanVector[i];
        difference = current->getEnding() - current->getBeginning() + 1;
        totalFreeSpaces = totalFreeSpaces + difference;
    }

    //move everything in memory table up if the address above it is free
    for(int a = 1; a < memoryTable.size();a++)
    {
        if(memoryTable[a-1] == "free")
        {
            memoryTable[a -1] = memoryTable[a];
            memoryTable[a] = "free";
        }
    }

    for(int b = memoryTable.size()-totalFreeSpaces; b < totalFreeSpaces; b++)
    {
        memoryTable[b] = "free";
    }

    Spans* newSpan = new Spans(memoryTable.size()-totalFreeSpaces,totalFreeSpaces,free);

    newSpan->setBeginning(memoryTable.size()-totalFreeSpaces);
    newSpan->setEnding(totalFreeSpaces);

    resetSpanVector(spanVector);

    spanVector.push_back(newSpan);
}
Ejemplo n.º 6
0
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);

}