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.

עברית

זיכרון סטק לעומת זיכרון היפ

  • משתנים מקומיים רגילים מתגוררים ב-סטק. הם מופיעים כשהפונקציה מתחילה ונעלמים כשהיא חוזרת.
  • לעיתים אתה צריך זיכרון ש-יחיה לאורך זמן מהפונקציה, או שאורכו ידוע רק בזמן הרצה.
  • הזיכרון הזה מגיע מה-היפ. אתה מבקש אותו, ולאחר מכן מחזיר אותו.

malloc לוקח בלוק זיכרון היפ ומחזיר רמז; free מחזיר את הבלוק

Handout · ⁨חומר עזר⁩

Log in or create account · ⁨היכנס או צור חשבון⁩

IGCSE, A-Level & AP