Merits and demerits of static and dynamic memory allocation
Asked by admin @ in Science viewed by 302 People
Advantages and disadvantages of static and dynamic memory allocation
Asked by admin @ in Science viewed by 302 People
Advantages and disadvantages of static and dynamic memory allocation
Answered by admin @
Static
allocation:
Advantages:
1. Static
allocation is done at compile time when you know the size of the array.
2. The
memory size allocated to “data” is static. But it is possible to change content
of a static structure without increasing the memory space allocated to it.
3. Global
variables are declared “ahead of time,” such as fixed array.
4. Lifetime
of Static allocation is the entire runtime of program.
5. It
has efficient execution time
Disadvantages:
1. In
case more static data space is declared than needed, there is waste of space.
2. In
case less static space is declared than needed, then it becomes impossible to
expand this fixed size during run time.
Dynamic Allocation:
Advantages:
·
Dynamic Allocation
is done at run time.
·
Data structures can grow and shrink to fit
changing data requirements.
·
We can
allocate (create) additional storage whenever we need them.
·
We can de-allocate (free/delete) dynamic space
whenever we are done with them.
·
Thus we can always have exactly the amount of
space required - no more, no less.
Disadvantages:
·
As the memory is allocated during runtime, it requires more
time.
·
Memory needs to be freed by the user when done. This is important as it is more likely to
turn into bugs that are difficult to find.
Asked by admin @ in Computer Science viewed by 254 persons
Asked by admin @ in Computer Science viewed by 297 persons
Asked by admin @ in Health viewed by 307 persons
Asked by admin @ in Social Sciences viewed by 279 persons
Asked by admin @ in Social Sciences viewed by 288 persons
Asked by admin @ in Economy viewed by 277 persons
Asked by admin @ in Physics viewed by 319 persons
Asked by admin @ in Economy viewed by 309 persons
Asked by admin @ in Social Sciences viewed by 333 persons
Asked by maham237 @ in World Languages viewed by 616 persons
Asked by wiki @ in Health viewed by 1252 persons
Asked by wiki @ in Social Studies viewed by 719 persons
Asked by vanshika149 @ in English viewed by 1112 persons
Asked by rajesh064 @ in English viewed by 1273 persons
Asked by jaylord7 @ in Mathematics viewed by 1067 persons
Asked by admin @ in Science viewed by 6192 persons
Asked by admin @ in Science viewed by 4810 persons
Asked by admin @ in Science viewed by 3896 persons
Asked by admin @ in Science viewed by 3828 persons
Asked by admin @ in Science viewed by 3262 persons
Asked by admin @ in Science viewed by 2263 persons
Asked by admin @ in Science viewed by 1753 persons
Asked by admin @ in Science viewed by 1331 persons
Asked by admin @ in Science viewed by 1300 persons
Asked by admin @ in Science viewed by 1255 persons
Asked by admin @ in Science viewed by 1244 persons
Asked by admin @ in Science viewed by 1112 persons