Docstoc

Implement Internal _ External Fragme

Document Sample
Implement Internal _ External Fragme Powered By Docstoc
					                              PROGRAM NO. -9

Aim: -WAP to Implement Internal & External Fragmentation of
memory.

#include<iostream.h>
#include<conio.h>

void internal();
void external();

void main()
{
 clrscr();
 int ch;
 cout<<"\t\tMEMORY FRAGMENTATION";
 cout<<"\n\t1.Internal";
 cout<<"\n\t2.External";
 cout<<"\n\nEnter your choice:";
 cin>>ch;
 switch(ch)
 {
 case 1:internal();
         break;
 case 2:external();
         break;
 default:cout<<"\n\nWrong choice";
 }
}
 getch();
 }

void internal()
{
int p,n,l,i,A[10];
 cout<<"Enter the no. of blocks:";
 cin>>n;
 cout<<"Enter the size of memory blocks:\n";
 for(i=0;i<n;i++)
  cin>>A[i];

cout<<"\nEnter the size of your process:";
cin>>p;

unsigned int ch,temp=100;
for(i=0;i<n;i++)
{
  if(temp>A[i]-p)
   {
    temp=A[i]-p;
    ch=i;
   }
 }
 if(temp==100)
    cout<<"!!Process size exceeds memory block size!!";
  else
   {
    cout<<"\nThe process causes internal fragmentation";
    cout<<"\nMemory available at block "<<ch+1<<" of size "<<A[ch];
    cout<<"\nMemory wastage:"<<A[ch]-p;
}
 }


void external()
{
int i,n,j,x,mem=0,a[5];
 cout<<"Enter the no. of memory blocks";
 cin>>n;
 cout<<"\nThe maximum memory block is of 100";
 cout<<"\nEnter the values of these memory blocks:\n";
 for(i=1;i<=n;i++)
  {
   cin>>a[i];
   if((a[i]+mem)<=100)
    {
     mem=mem+a[i];
    }
   else
    {
      cout<<" !!!Not enough memory remains!!!\n";
      i--;
    }
  }
 cout<<"\nMemory occupied:"<<mem;
 cout<<"\nMemory remaining:"<<100-mem;
 cout<<"\n\nWhich memory block do you want to delete:";
 cin>>j;
 cout<<"\nMemory block deleted";
 cout<<"\nMemory freed:"<<a[j];
 cout<<"\nMemory occupied:"<<mem-a[j];
 cout<<"\nMemory remaining:"<<100-mem+a[j];
 cout<<"\n\nEnter another memory block:";
 cin>>x;
 if(((x+mem)<=100)||(x<a[j]))
{
    x=a[i];
    cout<<"Memory allocated";
  }
 else if((x+mem-a[j])<=100)
          cout<<"\nMemory is available but is fragmented";
     else
          cout<<"\nNot enough memory remains";
}
                                     OUTPUT

MEMORY FRAGMENTATION
1.Internal
2.External

Enter your choice:1
Enter the no. of blocks:3
Enter the size of memory blocks:
25
55
10
Enter the size of your process:50

The process causes internal fragmentation
Memory available at block 2 of size 55
Memory wastage:5

MEMORY FRAGMENTATION
1.Internal
2.External

Enter your choice:2
Enter the no. of memory blocks4

The maximum memory block is of 100
Enter the values of these memory blocks:
55
15
10
25
        !!!Not enough memory remains!!!
10

Memory occupied:90
Memory remaining:10
Which memory block do you want to delete:2

Memory block deleted
Memory freed:15
Memory occupied:75
Memory remaining:25

Enter another memory block:15
Memory is available but is fragmented

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:6
posted:4/30/2012
language:English
pages:4
Description: This document contains Lab practicals of Operating System Lab for CSE students, under Kurukshetra University scheme.