Dynamic memory allocation ek
programming concept hai jahan par
aap program ke runtime mein
memory allocate kar sakte hain. Ye
aapko flexibility deta hai ki aap kitni
memory aapke program ke liye
allocate karna chahte hain, jab aap
program chal raha hota hai. Isse aap
program ke resources ko efficient
tarike se manage kar sakte hain. C/C++
mein, malloc() aur free() functions
dynamic memory allocation ko
manage karne ke liye use kiye jate
hain
Zaroor! Dynamic memory allocation
ka matlab hota hai ki aap program ke
runtime mein memory allocate kar
sakte hain, jab aapka program
execute
ho raha hota hai. Isse aapko ye
advantage milta hai ki aap memory ka
use jitna zaroori ho, utna hi kar sakte
hain aur bekar mein extra memory
occupy nahi hogi.
Jab aap program likhte hain, toh aap
memory ka ek fixed portion declare
karte hain. Lekin kuch cases mein,
aapko pata nahi hota ki aapko kitni
memory ki zaroorat padegi, jaise agar
aap user se data input le rahe hain
aur
uski quantity pehle se fix nahi hai. Is
situation mein aap dynamic memory
allocation ka use karke program ko
itni memory provide kar sakte hain,
jitni aapko actual mein chahiye hoti
hai.
C/C++ mein, malloc() aur free()
functions ka use hota hai dynamic
memory allocation ke liye. malloc()
function aapko memory allocate
karne
mein madad karta hai aur free()
function allocated memory ko release
kar deta hai jab aapka program us
memory ki zaroorat nahi rakhta. Is
tarah se aap memory ko efficient
tarike se manage kar sakte hain aur
wastage ko kam kar sakte hain.
Yeh approach aapko program ke performance mein sudhar dene mein madad karta hai, khaaskar jab aapko unpredictable ya changing memory requirements hote hain.
1 Comments
👍👍👍
ReplyDelete