For both fixed and dynamic memory allocation schemes, the operating system must keep list of each memory location noting which are free and which are busy. Then as new jobs come into the system, the free partitions must be allocated.
These partitions may be allocated by 4 ways:
1. First-Fit Memory Allocation
2. Best-Fit Memory Allocation
3. Worst-Fit Memory Allocation
First-Fit Memory Allocation:
This method keeps the free/busy list of jobs organized by memory location, low-ordered to high-ordered memory. In this method, first job claims the first available memory with space more than or equal to it’s size. The operating system doesn’t search for appropriate partition but just allocate the job to the nearest memory partition available with sufficient size.
As illustrated above, the system assigns J1 the nearest partition in the memory. As a result, there is no partition with sufficient space is available for J3 and it is placed in the waiting list.
Advantages of First-Fit Memory Allocation:
It is fast in processing. As the processor allocates the nearest available memory partition to the job, it is very fast in execution.
Disadvantages of Fist-Fit Memory Allocation :
It wastes a lot of memory. The processor ignores if the size of partition allocated to the job is very large as compared to the size of job or not. It just allocates the memory. As a result, a lot of memory is wasted and many jobs may not get space in the memory, and would have to wait for another job to complete.
Best-Fit Memory Allocation:
The best fit deals with allocating the smallest free partition which meets the requirement of the requesting process. This algorithm first searches the entire list of free partitions and considers the smallest hole that is adequate. It then tries to find a hole which is close to actual process size needed.
Advantage
Memory utilization is much better than first fit as it searches the smallest free partition first available.
Disadvantage
It is slower and may even tend to fill up memory with tiny useless holes.
Worst-Fit Memory Allocation :
In worst fit approach is to locate largest available free portion so that the portion left will be big enough to be useful. It is the reverse of best fit.
Advantage
Reduces the rate of production of small gaps.
Disadvantage
If a process requiring larger memory arrives at a later stage then it cannot be accommodated as the largest hole is already split and occupied
For both fixed and dynamic memory allocation schemes, the operating system must keep list of each memory location noting which are free and which are busy. Then as new jobs come into the system, the free partitions must be allocated.
These partitions may be allocated by 4 ways:
1. First-Fit Memory Allocation
2. Best-Fit Memory Allocation
3. Worst-Fit Memory Allocation
First-Fit Memory Allocation:
This method keeps the free/busy list of jobs organized by memory location, low-ordered to high-ordered memory. In this method, first job claims the first available memory with space more than or equal to it’s size. The operating system doesn’t search for appropriate partition but just allocate the job to the nearest memory partition available with sufficient size.
As illustrated above, the system assigns J1 the nearest partition in the memory. As a result, there is no partition with sufficient space is available for J3 and it is placed in the waiting list.
Advantages of First-Fit Memory Allocation:
It is fast in processing. As the processor allocates the nearest available memory partition to the job, it is very fast in execution.
Disadvantages of Fist-Fit Memory Allocation :
It wastes a lot of memory. The processor ignores if the size of partition allocated to the job is very large as compared to the size of job or not. It just allocates the memory. As a result, a lot of memory is wasted and many jobs may not get space in the memory, and would have to wait for another job to complete.
Best-Fit Memory Allocation:
The best fit deals with allocating the smallest free partition which meets the requirement of the requesting process. This algorithm first searches the entire list of free partitions and considers the smallest hole that is adequate. It then tries to find a hole which is close to actual process size needed.
Advantage
Memory utilization is much better than first fit as it searches the smallest free partition first available.
Disadvantage
It is slower and may even tend to fill up memory with tiny useless holes.
Worst-Fit Memory Allocation :
In worst fit approach is to locate largest available free portion so that the portion left will be big enough to be useful. It is the reverse of best fit.
Advantage
Reduces the rate of production of small gaps.
Disadvantage
If a process requiring larger memory arrives at a later stage then it cannot be accommodated as the largest hole is already split and occupied
Process
1. Input memory blocks with size and processes with size.
2. Initialize all memory blocks as free.
3. Start by picking each process and check if it can be assigned to current block.
4. If size-of-process <= size-of-block if yes then assign and check for next process.
5. If size-of-process >= size-of-block if yes then no assign
Process
1. Input memory blocks with size and processes with size.
2. Initialize all memory blocks as free.
3. Start by picking each process and check if it can be assigned to current block.
4. If size-of-process <= size-of-block if yes then assign and check for next process.
5. If size-of-process >= size-of-block if yes then no assign