Skip to content · ⁨الانتقال إلى المحتوى⁩

Dynamic memory: malloc, free, and realloc · ⁨الذاكرة الديناميكية: malloc, free, realloc⁩

English

Stack memory vs heap memory

  • Normal local variables live on the stack. They appear when a function starts and vanish when it returns.
  • Sometimes you need memory that outlives the function, or whose size you only know at run time.
  • That memory comes from the heap. You ask for it, and later you give it back.

العربية

ذاكرة المكدس مقابل ذاكرة الكومة

  • المتغيرات المحلية العادية تعيش على المكدس. تظهر عندما تبدأ الدالة وتختفي عند عودتها.
  • أحيانًا تحتاج إلى ذاكرة تبقى أطول من الدالة، أو whose حجم تعرفه فقط وقت التشغيل.
  • تأتي تلك الذاكرة من الكومة. تطلبها، وفي وقت لاحق تردها.

malloc تأخذ كتلة من ذاكرة المكدس وترجع مؤشراً؛ free تُعيد الكتلة

Handout · ⁨ورقة عمل⁩

Log in or create account · ⁨تسجيل الدخول أو إنشاء حساب⁩

IGCSE, A-Level & AP