I am a bit confused how glibc on linux allocates its memory to various program.These are the few questions:
-
Is it been allocated from a common heap(i.e is there a common heap
across all of the processes in linux) or is there one heap allocated
for every process in the system. -
Also suppose if I am compiling one static library and it finally gets statically linked to the main process, how it will get its memory? Is it already linked with some other heap(as we already compiled it) or will gets its memory from the main process’s heap.
There is no common heap in the
libcsense – this would violate process protection and virtual memory rules. Each process maintains its own heap. The kernel (with the help of the MMU in the processor) maintains the virtual memory tables which map virtual addresses to real memory.Static libraries are nothing more than linking code at compile time – there is no run time concept of a static library. It is one and the same as the process, and will use its heap.