Static and dynamic memory allocation

Static Memory AllocationDynamic Memory Allocation
1. In the static memory allocation, variables get allocated permanently, till the program executes or function call finishes.In the Dynamic memory allocation, variables get allocated only if your program unit gets active.
2. Static Memory Allocation is done before program execution.Dynamic Memory Allocation is done during program execution.
3. It uses stack for managing the static allocation of memoryIt uses heap for managing the dynamic allocation of memory.
4. It is less efficient It is more efficient
5. In Static Memory Allocation, there is no memory re-usabilityIn Dynamic Memory Allocation, there is memory re-usability and memory can be freed when not required.
6. In static memory allocation, once the memory is allocated, the memory size can not change.In dynamic memory allocation, when memory is allocated the memory size can be changed.
7. In this memory allocation scheme, we cannot reuse the unused memory.This allows reusing the memory. The user can allocate more memory when required. Also, the user can release the memory when the user needs it.
8 .In this memory allocation scheme, execution is faster than dynamic memory allocation.In this memory allocation scheme, execution is slower than static memory allocation.
9. In this memory is allocated at compile time.In this memory is allocated at run time.
10. In this allocated memory remains from start to end of the program.In this allocated memory can be released at any time during the program.
Posted on by