Computer Science, asked by Tweet5677, 1 year ago

Merit and demerit of dynamic and static memory allocation

Answers

Answered by hridhrita
0
Dynamic Arrays:

  You use them when you don't know at compile time the size of the array.
You only get the size requirement at run time.
   It is the programmers responsibility to free up the memory allocated for
these arrays. Otherwise, we can have memory leak.
   Also, since the memory is allocated at runtime, it takes more time.


Static Arrays:
      You use them when you  know at compile time the size of the array.
Size of this will not change during the execution of the program.
      Memory requirements works just as same for any other variable.
Programmer does not have to request, or free any memory.
      Since most of the work is done at run time, the program is faster.


Answered by Anonymous
0

Answer:

The scope and lifetime is limited

Only when globally defined its scope is not bounded

The amount of memory available through stack-based allocation is commonly far less than the amount of memory available through heap-based memory allocation.

Once you move out of the system,the memory crashes that is a very big disadvantage.

Merits :

It has automatic cleanup and no manual assistance is required for this process.It is best used when the size is already know to you.

Dynamic Memory Allocation:

Its is performed during run time and is assigned to heap.The size may or may not be known in starting.There is no particular order of assignment.

Similar questions