Memory allocation in programming is very important for storing values when you assign them to variables. The allocation is done either before or at the time of program execution. This eventually allocates memory for the variables declared by a programmer via the compiler.
The major difference between static and dynamic memory allocations are:
Static Memory Allocation | Dynamic Memory Allocation |
---|---|
In this case, variables get allocated permanently | In this case, variables get allocated only if your program unit gets active |
Allocation is done before program execution | Allocation is done during program execution |
It uses the data structure called stack for implementing static allocation | It uses the data structure called heap for implementing dynamic allocation |
Less efficient | More efficient |
There is no memory reusability | There is memory reusability and memory can be freed when not required |
Keep W3schools Growing with Your Support!
❤️ Support W3schools