Problem
No: 07
Name
of the problem: MFT memory management technique
Theory:
MFT (Multiprogramming with a Fixed number of
Tasks) is one of the old memory
management techniques in which the memory is partitioned into fixed-size partitions and each job
is assigned to a partition. The memory assigned
to a partition does not change.
Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int
n,i,tm,nob,p=0,bs,mr[20],ifrag[20],tif=0,tef=0,efrag[20];
cout<<"Enter the total memory
available(in bytes) ";
cin>>tm;
cout<<"Enter the block size (in
bytes) ";
cin>>bs;
cout<<"Enter the number of
process - ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter memory
required for process"<<i+1<<"(in bytes) -";
cin>>mr[i];
}nob=tm/bs;
cout<<"Number of blocks
available in memory
"<<nob<<endl;
cout<<"Process memory required\tallocated\tinternal
fragmentation"<<endl;
for(i=0;i<n&&p<nob;i++)
{
if(mr[i]<=bs)
{
ifrag[i]=bs-mr[i];
cout<<i+1<<"\t\t"<<mr[i]<<"\t\t"<<"YES"<<"\t\t"<<ifrag[i]<<endl;
p++;tif=ifrag[i]+tif;
}
else
{cout<<i+1<<"\t\t"<<mr[i]<<"\t\t"<<"NO"<<"\t\t-----"<<endl;
}
}
if(n>i){cout<<"memory is
full.remaining process can not be accommodated "<<endl;}
while(i<n){tef=tef+mr[i];i++;}
cout<<"total internal
fragmentation is :"<<tif<<endl;
cout<<"total external
fragmentation is :"<<tef<<endl;
}
Problem
No: 08
Name
of the problem: MVT
memory management technique
Theory:
MVT (Multiprogramming 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 from the problem of internal fragmentation and MVT
suffers from external fragmentation.
Code :
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,c=0,tmr=0,tmr1=0,temp,tm,mr[20];
char ch='y';
cout<<"Enter the total memory
available(in bytes) ";
cin>>tm;
for(i=0;ch=='y';i++)
{
cout<<"Enter memory required
for process"<<i+1<<"(in bytes) ";
cin>>mr[i];tmr1=tmr1+mr[i];
temp=tm-tmr1;
if(temp>0)
{
cout<<"memory is
allocated for process "<<i+1<<endl<<"D5o you want
to continue? ";
cin>>ch;c++; tmr=tmr+mr[i];
}
else
{
cout<<"Memory is
full"<<endl;break;
} }
cout<<"total memory available:
"<<tm<<endl;
cout<<"process memory allocated"<<endl;
for(i=0;i<c;i++)
{
cout<<i+1<<"\t\t"<<mr[i]<<endl;
}
cout<<"total memory allocated "<<tmr<<endl;
cout<<"total external
fragmentation "<<tm-tmr;
}
No comments:
Post a Comment