FirstFit ffMemory new FirstFit totVolume std vector procInfo curProc s

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
FirstFit *ffMemory = new FirstFit(totVolume);
std::vector<procInfo*> curProc;
std::vector<procInfo*> queueProc;
std::vector<unsigned int> junk;
std::vector<unsigned int> queueJunk;
for(unsigned int i=0; i<experTime; i++)
{
//уменьшаем время
for(unsigned int j=0; j<curProc.size(); j++)
{
if(curProc[j]->execTime>0)
{
curProc[j]->execTime--;
}
if(curProc[j]->execTime==0)
{
curProc[j]->execTime=-1;
ffMemory->bFreeMemory(curProc[j]->id);
curProc[j]->finishTime = i;
//.erase(curProc.begin()+j);
//junk.push_back(j);
}
}
//ищем завершенные процессы и освобождаем память
/*for(unsigned int j=0; j<curProc.size(); j++)
{
if(curProc[j]->execTime==0)
{
ffMemory->bFreeMemory(curProc[j]->id);
curProc[j]->finishTime = i;
//.erase(curProc.begin()+j);
junk.push_back(j);
}
*///}
//выбрасываем их из массива
/*for(unsigned int j=0; j<junk.size(); j++)
{
curProc.erase(curProc.begin()+junk[j]);
}
*///junk.clear();
//ищем в очереди подходящие процессы и запоминаем их id
for (unsigned int j=0; j<queueProc.size(); j++)
{
//std::cout << ' ' << *it;
if(!queueProc[j]->qflag)
{
switch(ffMemory->ffAlocMem(queueProc[j]->memory,queueProc[j]->id))
{
case 0:
queueProc[j]->defrag = false;
queueProc[j]->startTime = i;
curProc.push_back(queueProc[j]);
queueProc[j]->qflag = true;
//queueJunk.push_back(j);
break;
case 1:
queueProc[j]->execTime+=fragTime;
queueProc[j]->startTime = i;
queueProc[j]->defrag = true;
queueProc[j]->qflag = true;
curProc.push_back(queueProc[j]);
//queueJunk.push_back(j);
break;
case 2:
break;
}
}
}
//добавляем его
// for(unsigned int j=0; j<queueJunk.size();j++)
// {
// queueProc.erase(queueProc.begin()+queueJunk[j]);
// }
// queueJunk.clear();
if(threadMap.find(i)!=threadMap.end())
{
std::cout<<"found "<<i<<std::endl;
threadMap[i].creatTime = i;
switch(ffMemory->ffAlocMem(threadMap[i].memory,threadMap[i].id))
{
case 0:
std::cout<<0;
threadMap[i].defrag = false;
threadMap[i].startTime = i;
curProc.push_back(&threadMap[i]);
break;
case 1:
std::cout<<1;
threadMap[i].execTime+=fragTime;
threadMap[i].startTime = i;
threadMap[i].defrag = true;
curProc.push_back(&threadMap[i]);
break;
case 2:
std::cout<<3;
queueProc.push_back(&threadMap[i]);
break;
}
}
std::cout<<"====== "<<i<<" ======"<<std::endl;
showproc(curProc);
//showmap(threadMap);
}
delete ffMemory;