Memory Allocation Algorithms
Memory Allocation Algorithms
1. First Fit
How it works:
Scan memory from the beginning and allocate the first free block that is large enough.
Example:
Free blocks: [100 KB, 500 KB, 200 KB, 300 KB]
Advantages:
Disadvantages:
2. Best Fit
How it works:
Find the smallest free block that is big enough for the request.
Example:
Free blocks: [100 KB, 500 KB, 200 KB, 300 KB]
Advantages:
Disadvantages:
- Slower (must search entire list), can create many small unusable holes.
3. Worst Fit
How it works:
Example:
Free blocks: [100 KB, 500 KB, 200 KB, 300 KB]
Advantages:
Disadvantages:
4. Next Fit
How it works:
Similar to First Fit, but it starts searching from where it last left off.
Example:
Free blocks: [100 KB, 500 KB, 200 KB, 300 KB]
After serving a previous request at 200 KB, it starts checking from 300 KB block next.
Advantages:
Disadvantages: