ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Operating Systems
    COMP3142
    Progress0 / 34 topics
    Topics
    1. Operating Systems Basics2. System Calls3. Process Concept and Scheduling4. Interprocess Communication5. Multithreaded Programming6. Multithreading Models7. Threading Issues8. Process Scheduling Algorithms9. Thread Scheduling10. Multiple-Processor Scheduling11. Synchronization12. Critical Section13. Synchronization Hardware14. Synchronization Problems15. Deadlocks16. Detecting and Recovering from Deadlocks17. Memory Management18. Swapping19. Contiguous Memory Allocation20. Segmentation and Paging21. Virtual Memory Management22. Demand Paging23. Thrashing24. Memory-Mapped Files25. File Systems26. File Concept27. Directory and Disk Structure28. Directory Implementation29. Free Space Management30. Disk Structure and Scheduling31. Swap Space Management32. System Protection33. Virtual Machines34. Operating System Security
    COMP3142›Contiguous Memory Allocation
    Operating SystemsTopic 19 of 34

    Contiguous Memory Allocation

    6 minread
    1,068words
    Intermediatelevel

    Contiguous Memory Allocation in Operating Systems

    Contiguous Memory Allocation is a memory management technique where each process is allocated a single, contiguous block of memory. In this approach, the entire memory required by a process is allocated as one contiguous section, meaning there are no gaps between memory addresses within the allocated space. Contiguous memory allocation is one of the simplest and oldest memory management schemes, used primarily in early operating systems.


    Basic Concept of Contiguous Memory Allocation

    In contiguous memory allocation:

    • Each process is given a single block of memory large enough to contain all of its code, data, and stack.
    • The operating system allocates memory to processes by assigning them a starting address and a length (size) in the memory. The process's code and data reside in consecutive memory locations.
    • The memory space for each process is allocated from the available free memory in a contiguous block, and when the process terminates, the memory is deallocated and returned to the free memory pool.

    How Contiguous Memory Allocation Works

    • Memory Partitioning: The system divides the available physical memory into two parts: one part for the operating system and one for the user processes.
    • Process Allocation: When a new process needs memory, the operating system looks for a sufficiently large contiguous block of free memory. Once found, the process is loaded into that block.
    • Memory Deallocation: When the process terminates, the memory is deallocated, and the space becomes free again, available for future processes.

    Advantages of Contiguous Memory Allocation

    1. Simplicity: The mechanism of contiguous memory allocation is easy to implement, as it involves allocating a single, continuous block of memory to each process.
    2. Efficiency: Since each process is loaded into a single contiguous block, memory access can be more straightforward, and hardware-level optimization (e.g., caching and memory access) can be easier to implement.
    3. Minimal Overhead: Unlike more complex memory management schemes like paging and segmentation, contiguous memory allocation has low overhead in terms of the management of memory blocks, as it does not require maintaining complex data structures like page tables.

    Disadvantages of Contiguous Memory Allocation

    1. Fragmentation:

      • External Fragmentation: Over time, as processes are loaded and unloaded, free memory can become fragmented into small blocks. As a result, even though the total free memory may be sufficient for a new process, it might not be available in a single contiguous block.
      • Internal Fragmentation: This occurs when a process is allocated more memory than it actually needs (e.g., allocating a fixed-size partition to a process that requires less memory). The unused memory within the allocated block remains wasted.
    2. Limited Flexibility:

      • The system has to allocate a single contiguous block of memory to a process. If the system does not find enough space in one large block, it cannot allocate memory to a new process, even if there are enough free memory areas scattered around.
    3. Difficult to Resize:

      • If a process needs to grow in size (e.g., due to dynamic memory allocation), it may not be able to do so unless there is enough contiguous free memory available. This is often difficult to guarantee, particularly in systems that have significant fragmentation.
    4. Inefficient Use of Memory:

      • If the system cannot find a sufficiently large contiguous block of memory to satisfy the request, it may have to wait until memory becomes free, potentially leading to delays.
    5. Complex Allocation and Deallocation:

      • Allocating large blocks of memory and managing their deallocation can become complex, especially in systems with many processes. It requires tracking which blocks are occupied and which are free.

    Types of Contiguous Memory Allocation

    1. Fixed Partitioning (Static Partitioning)

      • In fixed partitioning, the memory is divided into a set number of fixed-size partitions. Each partition is allocated to exactly one process. If a process is smaller than a partition, the unused portion of the partition is wasted (internal fragmentation).
      • Advantage: Simple and fast, with minimal bookkeeping.
      • Disadvantage: Wastes memory if a process is smaller than the partition, and external fragmentation is possible.
    2. Dynamic Partitioning (Variable Partitioning)

      • In dynamic partitioning, the memory is divided into partitions dynamically based on the size of the process. The OS allocates the exact amount of memory needed by a process.
      • Advantage: More flexible than fixed partitioning, as it uses memory more efficiently.
      • Disadvantage: Can lead to external fragmentation because free memory may not be in contiguous blocks.

    Allocation Strategies in Contiguous Memory Allocation

    1. First-Fit Allocation:

      • In this strategy, the OS searches for the first available block of free memory that is large enough to accommodate the process.
      • Advantage: Simple and quick.
      • Disadvantage: It can lead to external fragmentation, as smaller gaps are left in the memory after the process is allocated.
    2. Best-Fit Allocation:

      • The OS searches the entire list of free memory blocks and selects the one that is the smallest and large enough to accommodate the process. This minimizes wasted space.
      • Advantage: Minimizes wasted memory and external fragmentation.
      • Disadvantage: Can result in many small, unusable gaps (external fragmentation) and increases search time, especially in systems with many processes.
    3. Worst-Fit Allocation:

      • In this strategy, the OS selects the largest available block of free memory to allocate to a process.
      • Advantage: Reduces the chances of creating small, unusable gaps.
      • Disadvantage: May leave large, unused gaps that cannot be used efficiently later.

    Example of Contiguous Memory Allocation

    Consider a system with 1000 KB of physical memory. If three processes need to be allocated memory, the operating system might use contiguous memory allocation like this:

    Process Start Address End Address Size
    P1 0 KB 200 KB 200 KB
    P2 200 KB 500 KB 300 KB
    P3 500 KB 800 KB 300 KB
    Free 800 KB 1000 KB 200 KB

    In this case, each process is allocated a contiguous block of memory.


    Conclusion

    Contiguous memory allocation is a simple and effective technique for memory management in operating systems, where processes are allocated a single contiguous block of memory. However, it comes with some significant drawbacks, especially regarding fragmentation (both internal and external) and the inflexibility of memory allocation. These issues have led to the development of more advanced memory management schemes, such as paging and segmentation, which address fragmentation and allow for more efficient use of memory. Nonetheless, contiguous memory allocation is still useful in certain situations and provides an easy-to-understand memory management model.

    Previous topic 18
    Swapping
    Next topic 20
    Segmentation and Paging

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time6 min
      Word count1,068
      Code examples0
      DifficultyIntermediate