Linkers, Loaders & Executables
Memory allocated with C's malloc generally comes from which area of a process?
- AThe .text section
- BThe heap
- 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.