Heap Allocation: The memory is allocated during the execution of instructions written by programmers.
How is memory allocated on the heap?
A heap is a general term used for any memory that is allocated dynamically and randomly; i.e. out of order. The memory is typically allocated by the OS, with the application calling API functions to do this allocation.
When should I allocate on the heap?
You should use heap when you require to allocate a large block of memory. For example, you want to create a large size array or big structure to keep that variable around a long time then you should allocate it on the heap.