A range of memory that the operating system allocates as needed for a program. Multiple ranges can be allocated with multiple requests.

The malloc and free functions in C deal with the heap.

Properties, Pros and Cons

PropertiesImplications
Size is dynamicβœ… You can store a large amount of memory without worrying about stack overflows
βœ… You can store data structures of dynamic sizes
🚫 System Call for additional memory is slow
Inherently fragmentedβœ… Allows for data structure of dynamic sizes
🚫 Requires keeping track of a vtable, which takes up a bit of cycles and memory.
🚫 Allocations within the heap requires searching through sub-regions in the heap
Memory has to be manually managed🚫 Leading to runtime errors common to many low-level languages
Fast accessing times if used correctly

Note

Using a heap isn’t inherently slow. It depends on the data structure used, and the allocation strategy.

Also, an allocation may not necessarily trigger a syscall. It may not if there ranges in the heap that can fit your data structure needs.