Memory concept in computers


#1

Why heap is used as dynamic memory and stack as static one?


#2

Stack is used for static memory allocation and Heap for dynamic memory allocation, both are basically stored in the computer’s RAM . The foremost thing to be noticed is that variables allocated on the stack are stored directly to the memory and access to this memory is very fast, and it’s allocation is dealt with when the program is compiled.
On the other hand
Heaps are used in programming languages for memory allocation. The values assigned in a heap are stored permanently and has to be deleted by the user itself i.e manually . Values on stack on the other hand will be deleted automatically once the function call ends. The reason for usage of the heap is that they are variable in size.


#3

Heap is used as dynamic memory because dynamic RAM contains more memory cells as compared to static RAM per unit area. Dynamic RAM stores the data as a charge on the capacitor. It contains of MOSFET and capacitor for each cell.
Stack is used a static memory because static RAM contains less memory cells per unit area. Static RAM consists of number of flip flops. Each flip flop stores one bit.