Search

Monday, February 3, 2014
0 comments

Advantage of dynamic over static memory allocation

8:25 AMMonday, February 3, 2014
When you have gone through the above static memory allocation concept, it is clear that the static memory allocation major disadvantages. To overcome those disadvantages dynamic memory allocation is used. That is the reason why dynamic memory allocation has many advantages over static memory allocation .

When main memory is allocated statically it cannot be altered during the execution of program. When main memory is allocated dynamically it can be altered during the execution of program as per the user wish. The length of dynamically allocated memory either can be decreased or increased. This is the major advantage of dynamic memory allocation over static memory allocation.

Suppose user wishes to enter elements of an array or a list one by one just after allocating memory and he may stop at any point then definitely it is not possible by means of static memory allocation. So the dynamic memory allocation certainly has an advantage in this case over static memory allocation. Such dynamically created list is called as linked list.

In case of dynamically created lists insertions and deletions can be done very easily just by the manipulation of addresses whereas in case of statically allocated memory insertions and deletions lead to more number of movements and wastage of memory.

In case of statically allocated memory there is every chance of “overflow”  during insertions in the lists, whereas in case of dynamically allocated memory it does not come into picture unless otherwise unavailability of main memory.

For some liner data structures like STACK and QUEUE, dynamic memory allocation proves very much appropriate because the length of such data structure is not fixed. They may increase or decrease dynamically that is during the execution of program. Similarly non-linear data structures need recursive definitions of   “struct” data type, so the need of dynamic memory allocation.
Once you go through the implementation of dynamic data structure the advantages of the same will be clear.  

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top