You are on page 1of 4

CourseName:Real Time System Lab Course Code: CSP-457

Experiment:3.1
Aim: Write a Program to simulate the MVT
Software Required: VS Code, C++ compiler
Description: MVT (Multi programming with a Variable number of Tasks) is the memory
management technique in which each job gets just the amount of memory it needs. That is, the
partitioning of memory is dynamic and changes as jobs enter and leave the system. MVT is a
more ``efficient'' user of resources. MFT suffers with the problem of internal fragmentation
and MVT suffers with external fragmentation.

Pseudo code/Algorithms/Flowchart/Steps:
Step1: Start the process.

Step2: Declare variables.

Step3: Enter total memory size ms.

Step4: Allocate memory for os.

Ms=ms+os

Step5: Read the no partition to be divided n Partition size=ms/n.

Step6: Read the process no and process size.

Step 7: If the process size is less than partition size alloys also block the process. While
allocating update memory wastage-external fragmentation.

Name: Shubham Bharti UID: 19BCS2848


CourseName:Real Time System Lab Course Code: CSP-457
Step 8: Print the results

Step 9: Stop

Implementation:
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{ int m = 0, m1 = 0, m2 = 0, p, count = 0, i;
cout << "Enter the memory capacity: "; cin
>> m; cout << "Enter the number of
processes: "; cin >> p;

int arr[p]={0};

for (i = 0; i < p; i++)


{ cout << "\nEnter memory req for process " << i + 1 << ": ";
cin >> m1; count = count + m1; if (m1 <= m)
{

Name: Shubham Bharti UID: 19BCS2848


CourseName:Real Time System Lab Course Code: CSP-457
if (count == m) cout << "There is no further
memory remaining."; arr[i]=m1; m2 = m - m1; m =
m2; } else
{ cout << "Memory is not allocated for process " << i + 1 << endl;
} cout << "External fragmentation for this process is: " << m2 <<
endl;
}

cout<<"process\t"<<"memory allocated"<<endl;
for(i=0;i<p;i++){
cout<<i+1<<"\t"<<arr[i]<<endl;
} return
0;
}

Output:

Name: Shubham Bharti UID: 19BCS2848


CourseName:Real Time System Lab Course Code: CSP-457

Name: Shubham Bharti UID: 19BCS2848

You might also like