Difference between Static allocation and Stack allocation
Static Allocation: Static allocation is a procedure which is used for allocation of all the data objects at compile time. Static allocation is possible only when the compiler knows the size of data object at compile time. In this type of allocation, formation of data objects is not possible under any circumstances at run time. In static allocation, compiler decides the amount of storage for each data object and binds the name of data objects to the allocated storage. Stack Allocation: Stack allocation is a procedure in which stack is used to organize the storage. The stack used in stack allocation is known as control stack. In this type of allocation, creation of data objects is performed dynamically. In stack allocation, activation records are created for the allocation of memory. These activation records are pushed onto the stack using Last In First Out (LIFO) method. Locals are stored in the activation records at run time and memory addressing is done by using pointers and registers. The difference between Static Allocation and Stack Allocation are as follows:
||Static Allocation does not makes data structures and objects dynamically.
||Stack allocation makes data structures and objects dynamically.
||In static allocation, allocation of all data objects is performed at compile time.
||While in stack allocation, allocation of data objects is performed at run time.
||It does not support recursive procedures.
||It supports recursive procedures.
||Static allocation is not able to manage the allocation of memory at run time.
||Stack allocation use stack to manage the allocation of memory at run time.
||In static allocation, at compile time the data object names are fixed.
||In stack allocation, index and registers performs the memory addressing.
||This strategy is easy and simple in implementing.
||This strategy is slower than static allocation.
||Occurs during compilation/linking
||Occurs during function call/return
||Manual management (explicit initialization)
||Automatic management (stack pointer manipulation)
||Global variables, static variables
||Local variables, function parameters
||Fixed memory address
||Relative to the current stack frame
Level Up Your GATE Prep!
Embark on a transformative journey towards GATE success by choosing Data Science & AI
as your second paper choice with our specialized course. If you find yourself lost in the vast landscape of the GATE syllabus, our program is the compass you need.