CONTIGUOUS MEMORY ALLOCATION
CONTIGUOUS MEMORY ALLOCATION
First Fit
In the first-fit, operating system searches for the first free partition that is large enough to
accommodate the process. The operating system starts searching from the beginning of the
memory and allocates the first free partition that is large enough to fit the process.
Example:
Let’s assume the memory has the following free blocks:
[100 KB, 500 KB, 200 KB, 300 KB, 600 KB]
A process of 250 KB requests memory.
Best Fit
The best-fit algorithm searches for the smallest free partition that is large enough to
accommodate the process. The operating system searches the entire memory and selects the
free partition that is closest in size to the process. If an exact fit is found, no memory is
wasted.
Example:
Using the same free blocks:
[100 KB, 500 KB, 200 KB, 300 KB, 600 KB]
A 250 KB process needs memory.
-The OS looks at all available blocks and finds that 300 KB is the closest match.
-The process is placed in the 300 KB block.
-50 KB remains free.
Worst Fit
The worst-fit algorithm searches for the largest free partition and allocates the process to it.
This algorithm is designed to leave the largest possible free partition for future use.
Example:
Using the same free blocks:
[100 KB, 500 KB, 200 KB, 300 KB, 600 KB]
A 250 KB process needs memory.
Best Fit reduces external fragmentation by allocating processes to the smallest free partition,
but it requires more time to search for the appropriate partition.
Worst Fit reduces external fragmentation by leaving the largest free partition, but it can lead
to inefficient use of memory.