Programming Languages Identify the difference between static
(Programming Languages)
Identify the difference between static, stack-based, and heap-based allocation, list and explain what each is used for.
Solution
Static allocation of memory is done when the memory requirement is known at the compile time. Stack based memory allocation is done whenever the storage requirements are not known earlier i.e. at the time of compilation but the requests which are made must obey the phenomenon of last in, first out i.e. LIFO. Heap Based Storage memory allocation is done when storage allocation is to be done during the execution of the program which means that the memory required need not to be specified in the starting, it can be allocated or de-allocated during the execution of the program.
Examples of Static based memory allocation : Assigning memory to constants in C language.
Examples of Stack based memory allocation : For assigning memory to local variable in a procedure.
Heap based memory allocation is also known as Dynamic allocation of memory as the memory is allocated and deallocated during the exection of a program. This type of memory allocation technique is usually a bit expensive than the others.
