OPERATING SYSTEM: Difference between Stack and Heap
Stack is used for static memory allocation and heap is used for dynamic memory allocation, both are located in the RAM of the computer. Variables allocated on the stack are stored directly in the memory. Access to this memory is very fast. This allocation is processed when the program is compiled. When a function or a method calls another function which in turn calls another function, etc., the execution of all these functions remains suspended until the last function returns its value. The stack is always reserved in LIFO order, the last reserved block is always the next block to be released. This makes stack tracking very simple, releasing a block from the stack is nothing more than adjusting a pointer. Memory is allocated to the variables assigned to the memory segment at runtime and access to this memory is a little slower, but the size of the memory segment is only limited by the size of the virtual memory. The elements of the heap have no dependency on each other a