-
Notifications
You must be signed in to change notification settings - Fork 0
/
MFT.cpp
47 lines (40 loc) · 1.18 KB
/
MFT.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int ms, bs, nob, ef, n, mp[10], tif = 0;
int i, p = 0;
cout << "Enter the total memory available (in Bytes): ";
cin >> ms;
cout << "\nEnter the block size (in Bytes): ";
cin >> bs;
nob = ms / bs;
ef = ms - nob * bs;
cout << "\nEnter the number of processes: ";
cin >> n;
for (i = 0; i < n; i++)
{
cout << "\nEnter memory required for process " << i + 1
<< " (in Bytes): ";
cin >> mp[i];
}
cout << "\nNo. of Blocks available in memory: " << nob;
cout << "\n\nPROCESS\t\tMEMORY_REQUIRED\t\tALLOCATED\tINTERNAL FRAGMENTATION";
for (i = 0; i < n && p < nob; i++)
{
cout << "\n " << i + 1 << "\t\t\t" << mp[i];
if (mp[i] > bs)
cout << "\t\tNO\t\t---";
else
{
cout << "\t\tYES\t\t" << bs - mp[i];
tif = tif + bs - mp[i];
p++;
}
}
if (i < n)
cout << "\nMemory is Full, Remaining Processes cannot be accomodated.";
cout << "\n\nTotal Internal Fragmentation is " << tif;
cout << "\nTotal External Fragmentation is " << ef;
return 0;
}