What is the heap?
The heap is where we can store things which need to exceed the lifetime of a function call. Typically in C we would allocate a block of memory using the “malloc” command. After we are done using the memory we have to remember to call “free” and give the memory back to the operating system.
If we do not remember to do this, then we are said to have “leaked” memory.
At a high level implementing malloc involves keeping collection of free blocks of memory in the heap - there is time involved in finding these blocks of memory. It’s a lot more work than allocating memory on the stack.