First Fit Program in C-Algorithm and Explanation

 

What is First Fit?

The First Fit memory allocation checks the empty memory blocks in a sequential manner. It means that the memory Block which found empty in the first attempt is checked for size.

But if the size is not less than the required size then it is allocated.

Advantage:

It is the fastest searching Algorithm as we not to search only first block, we do not need to search a lot.

Disadvantage:

The main disadvantage of First Fit is that the extra space cannot be used by any other processes.If the memory is allocated it creates large amount of chunks of memory space.

First Fit Memory Management Scheme:

In the First Fit Memory Management Scheme, we check the block in the sequential manner i.e we take the first process and compare its size with the first block.

If the size is less than the size of the first block then only it is allocated. Otherwise, we move to the second block and this process is continuously going on until all processes are allocated.

Algorithm of First Fit:

1 Step: START.

2 Step: At first get the no of processes and blocks.

3 Step: Allocate the process by if(size of block>=size of the process) then allocate the process else move to the next block.

4 Step: Now Display the processes with blocks and allocate to respective process.

5 Step: STOP.

We have discussed the working and the Algorithm. Now, we will see the program for First Fit in C.

1. First Fit Program in C

C

Output:

first fit program in c

2. First Fit Program in C++

C++

Output:

first fit program in c


No comments