Linkers, Loaders & Executables

Memory allocated with C's malloc generally comes from which area of a process?

  1. AThe .text section
  2. BThe heap
  3. CThe .rodata section
Show answer and explanation

Answer: B. The heap

The heap is the area from which a running program obtains memory of the size it needs and returns it with free when done. Its key feature is that sizes and lifetimes are decided at run time. malloc manages free space itself and asks the OS to enlarge the area when it runs short (through the brk or mmap system calls on Linux). Forgetting to call free leaves unused memory behind, which is a memory leak.

  • A. .text holds code and is not writable.
  • B. Correct. It is the area for memory obtained as needed at run time.
  • C. .rodata is a read-only area for constants.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. Which lists the typical memory layout of a process on Linux and similar systems from low to high addresses?
  2. What is the advantage of laying out the heap and stack so they grow in opposite directions with a large gap between them?
  3. Which describes static linking?
  4. What is an advantage of dynamic linking (shared libraries)?
  5. A dynamically linked program copied to another computer fails to start. What is the most likely cause?