Skip to content · ⁨Lompat ke konten⁩

Dynamic memory: malloc, free, and realloc · ⁨Memori dinamis: malloc, free, dan 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.

Bahasa Indonesia

Memori stack vs memori heap

  • Variabel lokal biasa tinggal di stack. Mereka muncul saat fungsi dimulai dan hilang saat fungsi selesai.
  • Terkadang Anda membutuhkan memori yang bertahan lebih lama dari fungsi, atau ukurannya baru diketahui saat waktu berjalan.
  • Memori itu berasal dari heap. Anda memintanya, dan nanti Anda mengembalikannya.

malloc takes a block of heap memory and returns a pointer; free gives the block back

Handout · ⁨Lembar Kerja⁩

Log in or create account · ⁨Masuk atau buat akun⁩

IGCSE, A-Level & AP