Stack

an abstract data type is a collection of elements or data that follow LIFO (last in, first out) processes

The stack has two main operations: push and pop
Push: adds an element to the stack
Pop: removes the most recently added element that was not yet removed

Stack overflow: when the stack runs out of memory (e.g. if you have a recursive function, function A calls function A, you could run out of stack memory if function A keeps recursively calling itself before returning the result – the stack wouldn’t pop until a result is returned in a certain function)

Stacks are commonly used in the RAM, using a stack pointer to keep track of free RAM (in conjunction with loader) – this is often called “the stack”, “call stack”, “program stack”, “run-time stack”, which is completely independent of the heap memory
Typically, it is important not to rely on the stack to store returns of functions, as they can be popped (and data lost) once the function on the top of a stack returns

Leave a comment