Hello,
I cant make an implementation of quick fit and I need someone to help me how to do it.
Below is the code for best fit, which finds the minimum block size, and stores the process there.
QuickFit relies on lazy coalescing. If you free a block of size n, you are very likely, in the near future, to allocate a block of size n, because what you really did was free an object of type A (sizeof(A) == n) and you are therefore fairly likely in the near future to allocate a new object of type A. So instead of returning the block to the general heap, and possibly coalescing it with nearby blocks, you just hang onto it, keeping it in a list of blocks of size n. The next time you allocate an object of size n, the allocator looks on the free list[n] to see if there are any blocks laying aroud to be reallocated, and if one is, your allocation is essentially instantaneous. Only if the list is empty do you revert to one of the slower algorithms
#include <iostream>
usingnamespace std;
int main()
{
int nBlocks,nProcess,blockSize[20],processSize[20];
cout<<" Enter the number of blocks: ";
cin>>nBlocks;
cout<<" Enter the number of processes: ";
cin>>nProcess;
cout<<" Enter the size of "<<nBlocks<<" blocks: ";
for(int i=0;i<nBlocks;i++)
cin>>blockSize[i];
cout<<" Enter the size of "<<nProcess<<" processes: ";
for(int i=0;i<nProcess;i++)
cin>>processSize[i];
for(int i=0;i<nProcess;i++)
{
int min = 9999;
bool flag = false;
int pos=0;
for(int j=0;j<nBlocks;j++) {
if(min > blockSize[j] && processSize[i]<=blockSize[j])
{
min = blockSize[j];
flag = true;
pos = j;
}
}
if(flag)
{
blockSize[pos] = blockSize[pos] - processSize[i];
cout<<"\n\n Process "<<i+1<<" is allocated to Block "<<pos+1;
}
else
{
cout<<"\n Process "<<i+1<<" cannot be allocated";
}
cout<<"\n Remaining Block size\n";
for(int j=0;j<nBlocks;j++)
cout<<" "<<blockSize[j];
}
return 0;
}