The terms Stack and Heap get thrown around a lot in the programming world. But what does it means? What is the difference between them and why should we care?
To start, I would like to make a clarification on a possible misconception. Heap is referred here as a memory allocation technique, not as a data structure. Furthermore, when we speak about Heap as opposed to Stack, we do not mean two types of memory, what we mean is two ways of allocating memory.
When your code compiles (or run if interpreted), the compiler needs to consider how to allocate your variable definitions in memory. To understand this process, let’s first examine the pros and cons of each type of allocation.Continue reading What’s all the hype about the heap and Stack?