Why do I need to know the difference between heap and stack? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why do I need to know the difference between heap and stack?

It's memory. I don't care where it comes from or where it is stored. And it's the compilers job to figure out the best place for my data.

24th Jul 2016, 11:51 PM
Marco Neumann
Marco Neumann - avatar
1 Answer
0
it's more than just memory though. the stack lives and dies with function calls. once a function is called it's variables are pushed onto the stack. once the function ends the rsp returns clearing the stack. the heap however will stay there until it is called to be deleted. the question you have to ask yourself is "Do I want this to be alive for later use"
27th Jul 2016, 9:46 PM
destro