I'm new to Linux and C, just want to ask how brk
pointer grow after calling malloc.
We know that the kernel maintains a brk pointer that points to the top of the heap. let's say there is no available free blocks when we call malloc
to allocate the requested memory and we know malloc
call mmap
internally. Below is my questions:
Q1-when malloc
call mmap
internally, does malloc
pass brk
as the first argument to mmap
as starting address like:
//not 100% correct onlyfor demo purpose
// void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
void *malloc(size_t size){
...
mmap(brk, size,...);
... //line x
}
Q2- does other code section(after line x above) inside malloc
make brk
grow? or mmap
internally make the brk
grow?
malloc
. See stackoverflow.com/a/6485675/10622916.