we can use first fit memory management scheme to allocate memory space to different processes.Here is the program in c++
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class FFMM
{ int a[50],c,par,i,j,n,p[50],d[50],e[50],r,s,b;
public:
void input();
void output();
}X;
void FFMM::input()
{
c=1000;
r=c;
cout<<"Total memory Available = 1000";
cout<<"\nEnter the number of partition that you want in memory\t";
cin>>par;
cout<<"\nEnter the size of remaining partitions";
cout<<"\n\nRemaining Memory=\t1000";
for(i=0;i<par;i++)
{
if(r!=0)
{
cout<<"\n Partition "<<i+1<<"\t";
cin>>s;
r=r-s;
a[i]=s;
cout<<"\n Remaining Memory=\t"<<r;
}
}
cout<<"\n\nEnter the number of processes\t";
cin>>n;
cout<<"\nEnter the size of processes\n";
for(i=0;i<n;i++)
{
cout<<"\nP["<<i+1<<"] =\t";
cin>>p[i];
}
}
void FFMM::output()
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(p[i]<=a[j])
{
d[i]=j+1;
a[j]=a[j]-p[i];
break;
}
}
}
cout<<"\n\nThe Process allocation are as Follows\n";
cout<<"\nProcess\tPartition";
for(i=0;i<n;i++)
cout<<"\n P["<<i+1<<"]\t "<<d[i];
}
main()
{
X.input();
X.output();
getch();
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class FFMM
{ int a[50],c,par,i,j,n,p[50],d[50],e[50],r,s,b;
public:
void input();
void output();
}X;
void FFMM::input()
{
c=1000;
r=c;
cout<<"Total memory Available = 1000";
cout<<"\nEnter the number of partition that you want in memory\t";
cin>>par;
cout<<"\nEnter the size of remaining partitions";
cout<<"\n\nRemaining Memory=\t1000";
for(i=0;i<par;i++)
{
if(r!=0)
{
cout<<"\n Partition "<<i+1<<"\t";
cin>>s;
r=r-s;
a[i]=s;
cout<<"\n Remaining Memory=\t"<<r;
}
}
cout<<"\n\nEnter the number of processes\t";
cin>>n;
cout<<"\nEnter the size of processes\n";
for(i=0;i<n;i++)
{
cout<<"\nP["<<i+1<<"] =\t";
cin>>p[i];
}
}
void FFMM::output()
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(p[i]<=a[j])
{
d[i]=j+1;
a[j]=a[j]-p[i];
break;
}
}
}
cout<<"\n\nThe Process allocation are as Follows\n";
cout<<"\nProcess\tPartition";
for(i=0;i<n;i++)
cout<<"\n P["<<i+1<<"]\t "<<d[i];
}
main()
{
X.input();
X.output();
getch();
}
0 comments:
Post a Comment