+ 9

stack memory and heap memory

What is the difference between stack memory and heap memory?

15th Sep 2020, 7:31 PM
Ashwini Adsule
Ashwini Adsule - avatar
2 Respostas
+ 4
https://www.sololearn.com/discuss/1146851/?ref=apphttps://www.sololearn.com/discuss/1869415/?ref=apphttps://www.sololearn.com/discuss/239629/?ref=apphttps://www.sololearn.com/discuss/94942/?ref=app Stack is a linear data structure whereas Heap is a hierarchical data structure. Stack variables can't be resized whereas Heap variables can be resized. Stack memory is allocated in a contiguous block whereas Heap memory is allocated in any random order. © https://www.guru99.com/stack-vs-heap.html
15th Sep 2020, 7:36 PM
Nilesh
Nilesh - avatar
+ 1
Stack memory is used for local variables and the function callstack. Recall that stack traces look like this: from main.c 679:23 in main() from main.c 677:5 in foo() from main.c 238:3 in bar() Whenever a function is called, the return address is placed at the top of the stack. When a function returns, the program removes and jumps to the instruction stored at the top of the stack. Heap memory is used for all dynamic memory allocation. The details of dynamic memory allocation are somewhat implementation dependant, but in short, dynamic memory allocation is used to implement arrays and hashes/maps/hashmaps/associative arrays.
11th Dec 2020, 6:39 PM
SapphireBlue
SapphireBlue - avatar