Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do different programs gets their memory from a common heap or from a separate heap?

I am a bit confused how glibc on linux allocates its memory to various program.These are the few questions:

  1. 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.

  2. 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.

like image 217
pjain Avatar asked Aug 31 '11 05:08

pjain


People also ask

Do different processes share the heap?

The virtual memory for a process will be different from other process. Every process will get separate heap, stack independent of other process.

How is memory allocated on the heap?

A heap is a general term used for any memory that is allocated dynamically and randomly; i.e. out of order. The memory is typically allocated by the OS, with the application calling API functions to do this allocation.

Where does heap memory come from?

Heap memory is a part of memory allocated to JVM, which is shared by all executing threads in the application. It is the part of JVM in which all class instances and are allocated. It is created on the Start-up process of JVM. It does not need to be contiguous, and its size can be static or dynamic.

Is heap allocated per process?

Heap — This segment contains all memory dynamically allocated by a process.


1 Answers

  1. There is no common heap in the libc sense - 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.

  2. 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.

like image 86
Yann Ramin Avatar answered Sep 24 '22 15:09

Yann Ramin