📚

Various allocation methods in Contiguous Memory Management

Jul 5, 2024

Various Allocation Methods in Contiguous Memory Management

Introduction

  • 4 algorithms for allocating memory to processes:
    • First Fit
    • Next Fit
    • Best Fit
    • Worst Fit

Scenario Setup

  • Memory contains processes and available holes (leftover space)
  • Processes: P10, P11, P12, P13, P14, P15
  • Objective: Allocate processes in available holes using different algorithms

First Fit Algorithm

  • Concept: Allocate the first hole that is big enough
  • Example:
    • Process P1 of size 15K
    • Find the first hole of 25K to allocate P1
    • Searching stops as soon as a suitable hole is found
  • Advantages:
    • Easiest and fastest method
    • Minimal searching time
  • Disadvantages:
    • May create large leftover holes, leading to inefficient usage of memory

Next Fit Algorithm

  • Concept: Same as First Fit, but starts searching from the last allocated hole
  • Example:
    • P1 allocated to a 25K hole
    • When P2 (18K) arrives, starts searching from 25K hole onwards
    • Finds a 40K hole and allocates P2
  • Advantages: Faster than First Fit when dealing with multiple allocations as it avoids repeated searches from the beginning

Best Fit Algorithm

  • Concept: Search entire list and choose hole that results in minimum internal fragmentation
  • Example:
    • Process P1 of size 15K
    • Searches all holes, tries to minimize leftover space
    • Allocates to a 20K hole, leaving 5K leftover
  • Advantages: Minimizes internal fragmentation
  • Disadvantages:
    • Very slow due to exhaustive search
    • May create tiny holes that are unusable for larger processes

Worst Fit Algorithm

  • Concept: Select the largest hole available
  • Example:
    • Process P1 of size 15K
    • Allocates to 100K hole, leaving 85K leftover
  • Advantages:
    • Keeps large leftover spaces which can accommodate future processes
  • Disadvantages:
    • Slow due to need to search entire list

Comparison

  • First Fit:
    • Easiest, fastest
    • May create many small leftover holes
  • Next Fit:
    • Modified First Fit
    • Faster as it avoids repeated searches from start
  • Best Fit:
    • Minimizes internal fragmentation
    • Very slow, may create tiny unusable holes
  • Worst Fit:
    • Opposite of Best Fit
    • Keeps large leftover spaces, but also slow

Conclusion

  • First Fit is generally the most convenient method due to speed
  • Depending on scenario, any algorithm might be best suited
  • Important to understand the working principles of these algorithms for practical application