Heap vs stack | Sololearn: Learn to code for FREE!
+ 6

Heap vs stack

In my university I learnt that when a programme is been executing the RAM will have many sections or parts two of them are stack and heap Is there any variation between them ? is stack faster than heap regarding any address in ram can be reached in the same time

3rd Feb 2019, 8:38 PM
ABADA S
ABADA S - avatar
2 ответов
+ 4
The stack is faster because the data is contiguous. The heap is slower because data has to be accessed at somewhat random locations. In addition to that, the program has to request and free the memory from the operating system which takes time.
3rd Feb 2019, 8:43 PM
Division by Zero
+ 3
Thanks Division by Zero you sold me
3rd Feb 2019, 8:49 PM
ABADA S
ABADA S - avatar