Difference between Static and Dynamic Memory allocation



Static Memory Allocation
  1. In this case, variables get allocated permanently
  2. Allocation is done before program execution (compile time)
  3. It uses the data structure called stack for implementing static allocation
  4. Less efficient
  5. There is no memory reusability

Example: primitive data type

Dynamic Memory Allocation
  1. In this case, variables get allocated only if your program unit gets active
  2. Allocation is done during program execution (run time)
  3. It uses the data structure called heap for implementing dynamic allocation
  4. More efficient
  5. There is memory reusability and memory can be freed when not required
Example: object, pointer variable

Post a Comment

0 Comments