4.2.23 · D1 · HinglishOperating Systems

FoundationsMemory allocation — contiguous (first-fit, best-fit, worst-fit)

1,958 words9 min read↑ Read in English

4.2.23 · D1 · Coding › Operating Systems › Memory allocation — contiguous (first-fit, best-fit, worst-f

Pehle hum "first-fit vs best-fit" ki baat kar sakein, usse pehle humein har woh word samajhna hoga jis par parent note ne rely kiya tha: cell, address, block, hole, base + length, the set symbol , size , the request , the inequality , aur leftover . Hum inhe ek ek picture se build karenge.


1. A memory cell and its address

Yeh topic ko kyun chahiye. Har baad wala idea — "base par ek block", "address 200 se 400 tak ek hole" — bas inhi numbered boxes ka ek range hai. Agar aap addresses ka ruler nahi dekh sakte, toh (base, length) ki koi bhi language samajh nahi aayegi. Address, memory ka coordinate system hai.


2. A block: base + length

"Contiguous" (unbroken) kyun matter karta hai. Ek program expect karta hai ki uski memory ek seedhi stretch ho taaki woh simple counting se cell to cell ja sake (, phir , phir ...). Agar OS use do alag pieces deta, toh address kisi aur ki memory mein land ho sakta tha. Woh ek word — contiguous — hi puri wajah hai ki placement mushkil hai.


3. A hole: free space between blocks

Yeh topic ko kyun chahiye. Poora game yeh hai: ek program room maangta hai, aur OS ko ek big enough hole dhundhnaa padta hai. Parent note ki "Swiss cheese" picture exactly figure s03 hai — filled blocks (busy) aur holes (free) ek dusre ke baad aate hain. Placement rules sab kaunsa hole choose karein ke liye recipes hain.


4. The free list and the set symbol

Yeh notation kyun. Humein "saare holes" ki baat karni hai ye jaane bina ki kitne hain. Subscript humein general cheezein kehne deta hai jaise "har hole ke liye" instead of haath se likhne ke. Yeh sirf ek bookkeeping shorthand hai, kuch zyada nahi.


5. The request and the inequality

Inequality kyun, equals kyun nahi. Requests almost kabhi ek hole se exactly match nahi karti. Hum perfect-size hole demand nahi karte; hum big-enough waali demand karte hain, phir jo piece chahiye woh kaat lete hain. exactly usi "big enough" idea ko capture karta hai — poore topic ka sabse zyada use hone wala test.


6. Leftover: the subtraction

Yeh ek formula topic ka heart kyun hai. Har placement rule ko uske leftover se judge kiya jaata hai. Best-fit ko chhota (tight fit) banane ki koshish karta hai; worst-fit ko bada (reusable chunk) banane ki. Subtraction literally woh number hai jis par first-fit, best-fit, aur worst-fit argue karte hain.


7. Fragmentation: two flavours

Dono kyun matter karte hain. Yeh do words un failure modes ko naam dete hain jiske against placement rules ladte hain. Poori treatment ke liye Fragmentation dekho; yahaan humein bas inhe picture se pehchanna hai: external = blocks ke beech waste, internal = block ke andar waste.


Prerequisite map

Byte and address ruler

Block = base plus length

Hole = an empty block

Free list h1 h2 h3 with braces

Size bars of hole

Request size s

Fits test size ge s

Leftover H minus s

Fragmentation external and internal

Placement rules first best worst fit

Upar se neeche padho: address ruler blocks ko meaningful banata hai, blocks holes ko meaningful banate hain, holes ek free list mein ikatthe hote hain, size bars humein test karne dete hain, woh test aur leftover placement rules drive karte hain — aur leftovers fragmentation mein pile up ho jaate hain. Ab parent note (parent topic) plain English ki tarah padha jaayega.


Equipment checklist

Right side cover karo aur answer karo; check karne ke liye reveal karo.

An address is
ek byte-box ki position ka permanent number memory line mein ().
A contiguous block is
consecutive boxes ki ek run jisme koi gap nahi, base aur length se describe ki jaati hai.
The last address of a block with base , length is
(nahi ).
The braces mean
saare current holes ka collection (set), subscript se tagged.
means
hole ka size (free boxes ki sankhya).
means
us memory request ka size jo ek program kar raha hai.
The test asks
kya yeh hole request jitna bada hai? (equality bhi fitting count hoti hai).
Why an inequality, not equals?
requests rarely ek hole se exactly match karti hain; humein bas "big enough" chahiye, phir piece kaat lete hain.
Leftover after placing in hole is
; agar toh hole vanish, warna base par ek chhota hole bachta hai.
External fragmentation is
kaafi total free memory, lekin aisi holes mein split jo har ek zyada chhoti hai (contiguous nahi).
Internal fragmentation is
allocated block ke andar waste free space.
Why is contiguity the whole difficulty?
ek program ko ek unbroken run chahiye, toh free ki request serve nahi kar sakta.