0

Explain stack and heap?

15th Jul 2017, 6:04 AM
Rahul.R
Rahul.R - avatar
2 Respuestas
+ 1
@Slak The heap size is also limited by the architecture. Example, a 32 bit process can only allocate 4gb total memory or less depending on the OS. Also, ram is not the limit. The OS uses virtual memory from the HDD/SSD, so you can actually allocate more memory than the amount of ram you have
15th Jul 2017, 7:04 AM
aklex
aklex - avatar
0
I will explain how I under stand it so if I am wrong please correct me: Stack: Stack is used for general variables where the size should be known before the time. Example: int i[10]; A new array of 10 elements is declared. The memory in the stack is also very limited so for large programs it is beter to use heap. Heap: The size of your variable does not necessarily need to be known before time. Example: int *i; i = new int[x]; A new array of x elements is declared. The heap make use of dynamic variable memory allocation, that is why we use pointers. Dynamic just means random location. Heap is also stored on the RAM so the size is limited to GB depending on the system. It is unlikely that you would run out of memory on the heap.
15th Jul 2017, 6:26 AM
Slak
Slak - avatar