Best Fit Program Using Memory Allocation-1
Best Fit Program Using Memory Allocation-1
#include<stdoio.h>
void main()
int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999;
scanf("%d",&nb);
scanf("%d",&np);
for(i=1;i<=nb;i++)
printf("Block no.%d:",i);
scanf("%d",&b[i]);
}
for(i=1;i<=np;i++)
printf("Process no.%d:",i);
scanf("%d",&p[i]);
for(i=1;i<=np;i++)
for(j=1;j<=nb;j++)
if(barray[j]!=1)
temp=b[j]-p[i];
if(temp>=0)
if(lowest>temp)
{
parray[i]=j;
lowest=temp
fragment[i]=lowest;
barray[parray[i]]=1;
lowest=10000;
printf("\nProcess_no\tProcess_size\tBlock_no\tBlock_size\
tFragment");
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t
%d",i,p[i],parray[i],b[parray[i]],fragment[i]);
}
Out put:
Block no.1:200
Block no.2:300
Block no.3:400
Block no.4:500
Block no.5:600
Process no.1:250
Process no.2:365
Process no.3:456
Process no.4:567
Process no.5:645
Process_no Process_size Block_no Block_size Fragment
1 250 2 300 50
2 365 3 400 35
3 456 4 500 44
4 567 5 600 33
--------------------------------
#include<stdio.h>
void main()
{
int bsize[10], psize[10], bno, pno, flags[10], allocation[10], i,
j;
flags[i] = 0;
allocation[i] = -1;
scanf("%d", &bno);
scanf("%d", &bsize[i]);
scanf("%d", &pno);
allocation[j] = i;
flags[j] = 1;
break;
if(flags[i] == 1)
printf("%d\t\t\t%d",allocation[i]+1,psize[allocation[i]]);
else
printf("Not allocated");
Output:
10
12
14
12
1 8 Not allocated
2 10 Not allocated
3 12 3 12
--------------------------------
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
scanf("%d",&nb);
scanf("%d",&nf);
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
for(i=1;i<=nf;i++){
printf("File %d:",i);
scanf("%d",&f[i]);
for(i=1;i<=nf;i++)
for(j=1;j<=nb;j++)
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
ff[i]=j;
highest=temp;
}
Output:
Block 1:40
Block 2:56
Block 3:76
Block 4:56
File 1:25
File 2:43
File 3:54
File 4:65
File_no File_size Block_no Block_size Fragment
1 25 3 76 51
2 43 2 56 13
3 54 4 56 2
4 65 0 4 0
frag[i]=highest;
bf[ff[i]]=1;
highest=0;
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();