Skip to content · ⁨コンテンツへスキップ⁩
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.

日本語

スタックメモリ vs ヒープメモリ

  • 通常のローカル変数はスタック上に存在します。関数が開始すると現れ、終了すると消えます。
  • 時折、関数の寿命を超えて残るメモリが必要だったり、サイズを実行時にしか分からない場合があったりします。
  • そのメモリはヒープから取得します。要求して、後に返します。

malloc はヒープメモリのブロックを要求しポインタを返します; free はブロックを返します

Handout · ⁨プリント⁩

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP