e v m

Stack vs Heap

August 11, 2020
0 Comments

Stack: Last in, first out. Think of pancakes, you start to eat from the warmest one. If you wanted to eat from the first one think of how the process of cooking pancakes and serving them would be complicated. Things on the stack must be of fixed size.

When you call a function it is pushed to the stack with its variables, and when it is over it is popped off.The values(arguments) you provide to the function are provided to the function with pointers to the heap which are also stored in the stack.

Heap: on the other hand is less organized. The size may not be fixed. Operating system allocates some space (not exact) on the heap and returns a pointer.


Emil Martinov

Written by Emil Martinov who lives Rotterdam || Istanbul and loves everything js. He tweets mostly about js.