Я пишу программу, которая показывает методы FIFO и LRU Allocation. Я могу произвести адреса памяти и получить строковые значения ссылок из адресов. Когда я пытаюсь запрограммировать часть FIFO, моя программа должна отбрасывать похожие значения. Например, если ссылочными строками являются 1, 5, 3, 2, 5 и имеется 4 доступных страницы, я знаю, что 1, 5, 3, 2 будут результирующими используемыми кадрами. Моя программа сохранит последние 5 из этого набора. Я расстался, где я думаю, что моя проблема в моей программе. Я включил все, только если я не прав.
#include <iostream>
#include <ctime>
#include <stdio.h>
#include <cstdlib>
#include <unistd.h>
#include <vector>
using namespace std;
int main() {
srand((unsigned)time(0));
int numPages, numFrames, size;
cout <<"***************************************\n";
cout <<"* Welcome to My Project *\n";
cout <<"*Below Are Examples of Page Allocation*\n";
cout <<"***************************************\n";
cout <<"Please enter the number of pages to use: ";
cin >> numPages;
cout << "Please enter the number of frames to allocate: ";
cin >> numFrames;
cout << endl;
int pageArray[numPages];
int frameArray[numFrames];
vector<int> frameArrayCounter;
vector<int> frameList;
vector<int> newFrameList;
for (int x = 0; x < numPages; x++) {
pageArray[x] = rand() % 500;
if (pageArray[x] == pageArray[x-1])
x -= 1;
if (pageArray[x] > 999)
pageArray[x] -= 100;
if (pageArray[x] < 100)
x -= 1;
}
cout << "The address sequence is as follows: " << endl;
size = sizeof(pageArray)/sizeof(pageArray[0]);
for (int x = 0; x < size; x++){
cout << pageArray[x] << " ";
frameList.push_back(pageArray[x]/100);
if ((x+1) % 10 == 0 )
cout << endl;
}
cout << endl;
newFrameList.push_back(frameList.at(0));
for (int x = 1; x < size; x++){
if (frameList.at(x) != frameList.at(x-1))
newFrameList.push_back(frameList.at(x));
}
cout << "The reference string is as follows: " << endl;
for (int a = 0; a < newFrameList.size(); a++)
cout << newFrameList.at(a) << " ";
cout << endl;
frameArrayCounter.push_back(newFrameList.at(0));
cout << "Below are the allocations for FIFO Page Allocation." << endl;
cout << "---------------------------------------------------\n" << endl;
*****************This is the area where I compute the FIFO allocation**************************
cout << frameArrayCounter.at(0) << endl;
for (int y = 0; y < newFrameList.size(); y++) {
for (int x = 0; x < numFrames; x ++) {
if (frameArrayCounter.at(x) == newFrameList.at(y))
break;
else if (frameArrayCounter.size() < numFrames){
frameArrayCounter.push_back(newFrameList.at(y));
for (int i = 0; i < frameArrayCounter.size(); i++)
cout << frameArrayCounter.at(i) << " ";
cout << endl;
break;
}
else {
frameArrayCounter.erase(frameArrayCounter.begin());
frameArrayCounter.push_back(newFrameList.at(x));
for (int i = 0; i < frameArrayCounter.size(); i++)
cout << frameArrayCounter.at(i) << " ";
cout << endl;
}
}
}
return 0;
}
Пример вывода:
***************************************
* Welcome to My Project *
*Below Are Examples of Page Allocation*
***************************************
Please enter the number of pages to use: 10
Please enter the number of frames to allocate: 3
The address sequence is as follows:
125 379 413 277 421 304 458 273 493 131
The reference string is as follows:
1 3 4 2 4 3 4 2 4 1
Below are the allocations for FIFO Page Allocation.
---------------------------------------------------
1
1 3
1 3 4
3 4 1
4 1 3
1 3 4
3 4 1
4 1 1
1 1 3
1 3 4
3 4 1
4 1 3
1 3 4
3 4 1
4 1 1
Ожидаемый вывод:
***************************************
* Welcome to My Project *
*Below Are Examples of Page Allocation*
***************************************
Please enter the number of pages to use: 10
Please enter the number of frames to allocate: 3
The address sequence is as follows:
125 379 413 277 421 304 458 273 493 131
The reference string is as follows:
1 3 4 2 4 3 4 2 4 1
Below are the allocations for FIFO Page Allocation.
---------------------------------------------------
1
1 3
1 3 4
2 3 4
2 1 4