I want to better understand how OS provides heap memory to a process. Here by he
ID: 651857 • Letter: I
Question
I want to better understand how OS provides heap memory to a process. Here by heap memory I mean the memory allocated dynamically, say by call to malloc.
When a process is newly created, does OS reserve some heap memory for it?
If a process calls malloc, does OS associate a "Page" (from paging concept) with process and then return some portion from that page? And so do later calls to malloc try to provide memory from this page, and if not possible OS associates another page from RAM(or virtual memory)?
Explanation / Answer
Heap allocators typically call a system call to reserve a region of pages and then dole out chunks of that to new, malloc, and other higher-level calls. The system call on Unix used to be brk and sbrk, but implementations sometimes use mmap as well. I think windows uses VirtualAlloc, but it's not totally clear to me. A good resource for this is Wikipedia's page on C dynamic memory allocation.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.