Untitled
unknown
plain_text
2 years ago
1.1 kB
9
Indexable
#include <iostream>
using namespace std;
const int MAX_BLOCKS = 3;
const int MAX_PROCESSES = 3;
void firstFit(int blockSize[], int processSize[], int m, int n) {
int allocation[MAX_PROCESSES];
for (int i = 0; i < n; i++) {
allocation[i] = -1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (blockSize[j] >= processSize[i]) {
allocation[i] = j;
blockSize[j] -= processSize[i];
break;
}
}
}
cout << "Process No.\tProcess Size\tBlock No." << endl;
for (int i = 0; i < n; i++) {
cout << " " << i + 1 << "\t\t" << processSize[i] << "\t\t";
if (allocation[i] != -1)
cout << allocation[i] + 1;
else
cout << "Not Allocated";
cout << endl;
}
}
int main() {
int blockSize[MAX_BLOCKS] = {5, 10, 20};
int processSize[MAX_PROCESSES] = {10, 20, 30};
int m = MAX_BLOCKS;
int n = MAX_PROCESSES;
cout << "First Fit Memory Allocation" << endl;
firstFit(blockSize, processSize, m, n);
return 0;
}
Editor is loading...
Leave a Comment