What Is Dynamic Memory Management?

Dynamic memory management is the memory that is given instantly to a program variable or data structure when it is needed. Here we are explaining this dynamic memory management phenomenon about the data structure.

In this blog post(Dynamic Memory Management), we will explore What you mean by dynamic memory management. What are static and dynamic memory?…

… What is the Dynamic Memory Allocation example? What are dynamic memory allocation and its types? What is compaction in memory management? What is the difference between compaction and fragmentation?|Dynamic Memory Management|

What do you mean by dynamic memory management?

There are many occasions when we don’t know about the memory needed by the program or program variable before compiling the program and running the program.

So this dynamic memory management helps us to handle the situation at compile time or static memory allocation.

It is the best help for us when we need a chunk of memory at the run time of the program. In most real-life problems, we need dynamic memory management.

In the multiprocessing computer environment, several programs reside in memory at the same time. a different program has different memory requirements.

For example, one program may require 50k of memory another requires 100k of memory and yet another requires 200k of memory.

Whenever there is a requirement by the operating system then it should be able to provide a contiguous block of memory of the right size.

When the execution process for a program is completed then it releases the memory and frees the block allocated to it and this freed block may be allocated to another program that needs it.

In the dynamic processing environment, the required memory is not known before the time of actual execution. Moreover, blocks of memory will, in general, be freed in some order different from that in which they are allocated.

At the start of the computer system, no jobs are in memory, so the whole memory says size M words are available for allocating to the programs. Now the jobs are submitted to the computer and the request is made for variable-size blocks of memory.

A large contiguous amount of storage may be required by a particular program such as a large array. So it would be impractical to entertain such a large block at a time,…

… similarly, a program may require a storage block in a large variety of sizes. In such cases, a dynamic memory management system must be able to process requests for a variable length of a block.

For example, consider a small memory of 1024 words, suppose a request is made for three blocks of storage that are 348, 110, and 212 words. it is assumed that these blocks are allocated sequentially as shown in Fig1 below.


Now suppose the second block of size 110 is freed, resulting in the situation shown in Fig 2. Now the 464 words of free space are available in noncontiguous blocks. Hence the request for 400 words can not be satisfied.

Suppose that block 3 is now freed clearly, it is not desirable to retain three blocks of 110, 212, and 354 words. Rather the blocks should be combined into a single large block of 676 words so that the further large request can be satisfied as shown in Fig 3.

What is static and dynamic memory?

Static memory is a form of pre-declared memory that is assigned to the variable at compile time of a program. Dynamic memory is allocated at the time of program execution and is also known as run-time memory allocation.

What is the Dynamic Memory Allocation example?

Sometimes the declared size of the array or memory is not sufficient at the run time then if a program or process requests any additional memory.

Like in the C/C++ program, we assign this memory at a run time manually with the use of some functions like MALLOC, CALLOC, RE-ALLOC, and FREE().

If we talk in the context of data structure then when a program requests memory at run time the OS provides a block of main memory and then the program uses…

… this memory for execution and once it is completed then returns the memory to other programs.

What is compaction in memory management?

Compaction is a process where every empty and unused memory block is collected together to form a large memory block that can be assigned to a process or program to execute successfully.

Compaction solves the problem of fragmentation where small unused memory blocks are left idle. A single block with some left memory may not be sufficient to fulfill the memory requirement of a program or process.

What is the difference between compaction and fragmentation?

As we know there are two types of fragmentation, one is internal fragmentation and another one is external fragmentation.

Internal fragmentation occurs when the process requires either less or more memory than the assigned fixed-size memory block.

External fragmentation occurs when we can not assign any memory block to the process as we have varying memory blocks that do not suit the process to fulfill the request.

To solve the problem of external fragmentation we use memory compaction and we collect the memory of all unused blocks make a large memory block and then assign it to a requested and best-suited process.

You can also go through a few more amazing blog links below related to Data Structure:

What is a strongly connected graph? / How do you know if a graph is strongly connected…
Graph: Types of the graph in data structure…
AVL Tree In Data Structure…
What is a tree in the data structure…
What is compaction in memory management…
What is garbage collection and how does it work…
Dynamic Memory Management…
Josephus problem & Circular linked list…
What is a circular linked list…
What are the linked lists in the data structure and their types…
What is the priority queue with an example…
the difference between stack and queue…
What is meant by backtracking in the data structure…


Thus this example of dynamic memory management shows us the necessity to keep track of available space, allocate portions of that space when allocation requests are made, and combine contiguous free spaces when a block is freed. If memory is free then it should be in a chunk so that it can be used by the program that needs a large block of memory.

What do you mean by dynamic memory management? What is static and dynamic memory? What is a Dynamic Memory Allocation example? What are dynamic memory allocation and its types? What is compaction in memory management?…….

….What is the compaction technique? What is compaction in computers? What is dynamic memory fragmentation? In this blog post, we have gone through.

In the case of any queries, you can write to us at a5theorys@gmail.com we will get back to you ASAP.

Hope! you would have enjoyed this post about dynamic memory management.

Please feel free to give your important feedback in the comment section below.

Have a great time! Sayonara!


I am a blogger by passion, a software engineer by profession, a singer by consideration and rest of things that I do is for my destination.