TheHingineer

  • Operating System


  • OS Part-1

  • OS Part-2

  • OS Part-3

  • OS Part-4

  • OS Part-5

  • Contiguous and Non-Contiguous Memory Allocation in Operating System

    Memory allocation ek important concept hai Operating System ka, jo decide karta hai ki processes ko RAM me kaise store kiya jaye. Do major types hote hain:

    1. 1. Contiguous Memory Allocation

    2. 2. Non-Contiguous Memory Allocation


    🔹 Contiguous Memory Allocation

    Is allocation method me, poori memory ek continuous block me allocate hoti hai. Matlab process ke sabhi instructions aur data ek single continuous block me store hote hain.

    ✅ Kaise Kaam Karta Hai?

    • Ek process ke liye ek continuous block of memory allocate kiya jata hai.

    • Process execution ke dauraan, wo memory block kisi aur process ko assign nahi kiya jata.

    🖼 Diagram (Contiguous Allocation)

    +----+----+----+------+----+------+------+
    | OS | P1 | P2 | Free | P3 | Free | Free |
    +----+----+----+------+----+------+------+

    ✅ Example:
    Agar ek process 200 KB ka hai, toh uske liye continuous 200 KB ka block allocate kiya jayega.

    ✅ Advantages:
    ✔ Fast Access: Kyunki memory continuously allocated hoti hai, isliye access speed fast hoti hai.
    ✔ Less Overhead: OS ko memory mapping aur fragmentation ka dhyan kam rakhna padta hai.

    ❌ Disadvantages:
    ❌ External Fragmentation: Chhoti-chhoti free memory gaps banti hain, jo naye processes ke kaam nahi aati.
    ❌ Fixed Size Allocation: Agar process chhoti hai, tab bhi poora allocated space use nahi hota (internal fragmentation).


    🔹 Non-Contiguous Memory Allocation

    Is allocation method me, process ka pura data ek single block me nahi hota, balki different memory blocks me store hota hai.

    ✅ Kaise Kaam Karta Hai?

    • Process ka data alag-alag blocks me store hota hai, jo alag-alag locations par hote hain.

    • Paging aur Segmentation is technique ka implementation karte hain.

    🖼 Diagram (Non-Contiguous Allocation – Paging Example)

    +----+-------+-------+------+-------+-------+-------+
    | OS | P1-Pg1| P3-Pg1| Free | P1-Pg2| P2-Pg1| P3-Pg2|
    +----+-------+-------+------+-------+-------+-------+

    Pg = Page (Process’s divided memory block)

    ✅ Example:
    Agar ek process 200 KB ka hai, aur RAM me 50 KB, 70 KB aur 80 KB ke free blocks available hain, toh process in blocks me todh kar store hoga.

    ✅ Advantages:
    ✔ No External Fragmentation: Memory efficiently use hoti hai.
    ✔ Better Memory Utilization: Chhoti-chhoti memory blocks bhi use ho sakti hain.
    ✔ Flexible Allocation: Badi processes split hoke multiple locations pe store ho sakti hain.

    ❌ Disadvantages:
    ❌ More Overhead: Process execution ke liye memory mapping aur address translation zaroori hoti hai.
    ❌ Slower Access: Kyunki data different memory locations pe hota hai, access speed kam ho sakti hai.


    🔹 Contiguous vs Non-Contiguous Memory Allocation

    Feature Contiguous Allocation Non-Contiguous Allocation
    Memory Allocation Single continuous block Multiple scattered blocks
    Fragmentation External & Internal Only internal fragmentation
    Speed Fast Slow (extra mapping required)
    Flexibility Low High (supports large processes)

    🔹 Conclusion

    ✔ Contiguous allocation simple aur fast hoti hai, lekin fragmentation ka issue hota hai.
    ✔ Non-contiguous allocation flexible hoti hai, jo memory utilization better karti hai, lekin slow ho sakti hai.
    ✔ Modern OS mostly non-contiguous memory allocation (Paging & Segmentation) prefer karte hain.

    Scroll to Top