All Programs are Written and Compiled in Dev C++. So, it may generate some error in case of other compilers and may need some modifications in program. Download Dev C++

Friday, 12 December 2014

Implement MVT with First Fit Memory Management Technique

AIM: Implement MVT with No of Partititon and Apply First Fit Memory Management.

#include<iostream>
using namespace std;
int  main()
{
    int tm,rm,os,n,i,ps,pn,pt[10],pt1[10];
    int fra1,fra2,tf=0,tp=0,flag=0,c=0;
    cout<<"Enter Total Memory: ";
    cin>>tm;
    cout<<"Enter Memory Given to OS: ";
    cin>>os;
    rm=tm-os;
    cout<<"Enter No of Partiotion: ";
    cin>>pn;
    cout<<"Enter The Size for Each Partition\n";
    for(i=0;i<pn;i++)
    {
    cout<<"\nPartition"<<i+1<<": ";
    cin>>pt1[i];
    if(tp+pt1[i]<rm)
    {

    pt[i]=pt1[i];
    tp=tp+pt[i];
    c=i+1;
    }
    else
    {
    cout<<"\nNot Enough Memory for Partition"<<i+1<<endl;
    }
   
    }
    cout<<"Enter No of Processes: ";
    cin>>n;
    for(i=0;i<n;i++)
    {
    if(c<=0)
    {
    cout<<"No Partition Available for Process"<<i+1<<endl;
    }
    else
    {
          cout<<"\nEnter Size of Process"<<i+1<<": ";
          cin>>ps;        
     for(int j=0;j<c;j++)
{
if(ps<=pt[j])
{
cout<<"Memory Allocated for Process"<<i+1<<" is="<<pt[j]<<endl;
              fra1=pt[j]-ps;
              cout<<"Internal Fragmentation="<<fra1<<endl;
              tf+=fra1;
              flag=1;
              for(int k=j;k<c;k++)
                     pt[k]=pt[k+1];
  c--;
              break;
}
else
flag=0;
}  
if(flag==0)
  {
    cout<<"Memory Not Allocated for Process"<<i+1<<endl;
   }
}
    }
    cout<<"\nTotal Internal Fragmentatio="<<tf<<endl;
    cout<<"External Fragmentation="<<rm-tp<<endl;
    return 0;
}

No comments:

Post a Comment