![]() |
VOOZH | about |
The stack is a segment of memory that stores temporary variables created by a function. In stack, variables are declared, stored and initialized during runtime.
When we compile a program, the compiler enters through the main function and a stack frame is created on the stack. A structure, also known as an activation record, is the collection of all data on the stack associated with one subprogram call. The main function and all the local variables are stored in an initial frame.
It is a temporary storage memory. When the computing task is complete, the memory of the variable will be automatically erased. The stack section mostly contains methods, local variables, and reference variables.
| It is stored in computer RAM just like the heap. |
| It is implemented with the stack data structure. |
| Stack memory will never become fragmented |
| It stores local variables and returns addresses, used for parameter passing. |
| Variables created on the stack will go out of scope and are automatically deallocated. |
| Variables created on the stack can be used without pointers. |
| We can use stack memory to store the data if we know exactly how much data you need to allocate before compile time and if it is not too big. |
| It usually allocates maximum sizes which are determined during the execution of the program. |
| Some issue like Stack overflow arises when too much of the stack memory is used (mostly from infinite or too deep recursion, substantial allocations). |