Untitled
unknown
plain_text
2 years ago
1.1 kB
9
Indexable
#include <iostream>
using namespace std;
void firstFit(int blockSize[], int processSize[], int m, int n) {
int allocation[n];
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[] = {100, 500, 200, 300, 600};
int processSize[] = {212, 417, 112, 426};
int m = sizeof(blockSize) / sizeof(blockSize[0]);
int n = sizeof(processSize) / sizeof(processSize[0]);
cout << "First Fit Memory Allocation" << endl;
firstFit(blockSize, processSize, m, n);
return 0;
}
Editor is loading...
Leave a Comment