answersLogoWhite

0


Best Answer
Two disadvantages of dynamic allocation: a) Freeing memory b) Fragmentation
Freeing MemoryThe user is responsible for freeing up memory when he is finished with it. This is a serious responsibility, a potential source of bugs that are very hard to find.

For example, suppose you free up a location before you're actually finished with it. Then further access to the location will either cause a run-time error (memory violation) or, what is worse (but more common), you will get access to a location that is being used for some completely unrelated purpose.

Trouble also occurs if you forget to free up some space. If you do this, you are losing the advantages of dynamic allocation. And in some circumstances - e.g. if you were writing the program that manages the space on a disk drive - this could be disastrous.

There are no surefire safeguards against these problems, you must be very careful when writing programs to return memory when you are finished with it, but not before.

Fragmentation of MemoryAs the preceding example demonstrated, with dynamic allocation the `free' parts of memory are not all together in one contiguous block. When we returned JOE's memory, we had 4 free cells on one side of MARYJANE and all the rest on the other side. This is called fragmentation of memory, and it can grow into a very serious problem: it is possible to have a large amount of free memory but for it to be broken up into such tiny fragments that there is not enough contiguous free space to store another name.

Suppose that after using dynamic allocation for a while memory becomes fragmented thus:

and that we need to obtain a block this big: If only the remaining free blocks were contiguous, we'd have enough room, but, in the present configuration, it looks like we are doomed. There are several possible solutions to this problem. The one we will study is based on the insight that a large data structure does not necessarily have to be allocated in one single contiguous chunk of memory. Instead it might be decomposed into smaller components that are somehow linked together in a chain.
User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the advantages and disadvantages of dynamic memory allocation and the allocation of files in secondary storage?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Compare and contrast dynamic memory allocation and the allocation of files in secondary storage?

Static Memory Allocation: Allocating the total memory requirements that a data structure might need all at once without regard for the actual amount needed at execution time. Dynamic Memory Allocation: The opposite strategy of static memory allocation - Dynamic Memory Allocation, involves allocating memory as-needed.


What is the opposite of dynamic allocation?

The opposite of dynamic is static.


Differentiate between static allocation and dynamic allocation?

BS Anwer- static allocation is when something is moved to a location permanantally and dynamic allocation is when something is moved temporarily, but will move again.


What are the two methods of representing a binary tree?

Two method of representing a binary tree is Static allocation, and Dynamic allocation


What is the use of Constructor with Dynamic allocation?

Constructors are necessary to initialize classes. It allows to avoid to a lot of problems with unauthorized access of memory. Dynamic allocation makes possible allocation of memory during execution of program. If you do not use dynamic allocation, all required memory will be allocated during initialization phase (constructors are usually responsible for that). But you can't use more memory. Dynamic allocation was designed to overcome such problems.


What is difference in static and dynamic storage allocation?

Static storage allocation is when a program dedicates an amount of memory for its use at the start of the program. Dynamic storage allocation is when a program only takes storage as it needs it.


What are types of memory allocation?

There are two types of memory allocations. 1. Static memory allocation 2. Dynamic memory allocation


What are the Advantages and disdvantages of dynamic model?

Advantages of dynamic model


How do you display matrix in c using dynamic memory allocation?

Memory allocation is not necessary to display a matrix.


What is the special features of pointers in c?

Dynamic memory allocation


What is the disadvantages and advantages of SAP implementation with SAP and stubs drivers?

This is very dynamic software. but the problem is what when you dont have your net connection you cannot use this.


What are the problem associated with dynamic memory allocation?

Not freeing it when you no longer need the memory.