What is compaction in memory management?

In this tutorial(What is compaction in memory management), I am going to explain one of the methods of dynamic memory management which is named compaction. In this process, all marked or used node is shifted to one end, and variable or available memory is kept at another end.

In this blog post(What is compaction in memory management), we will explore What is compaction in memory management? What is a compaction technique? What is dynamic memory fragmentation? What is storage compaction in data structure?

In a very simple language, compaction is a process in which we mode all the used nodes to the one end of the memory and all the available memory to the other end. The algorithm to perform such an operation is called the compaction algorithm.|What is compaction in memory management|

In this scheme initially, memory is one large block of available storage. When requests arrive for storage, a block of memory is allocated sequentially starting from the first location in the memory as shown in Fig-1.

A variable free point contains the address of the first location following the last block allocated as in Fig1, a free point equals 950. When a block is freed, the free point remains unchanged and no combination of free spaces takes place.

compaction-explanation

When a block of size n is allocated free point is increased by n. This continues until a block of size n is requested and free point+ n-1 is larger than the highest address in the memory. The request can not be satisfied without further action being taken.

At that point, user routines come to a halt and the system compaction routine is called. this routine copies all allocated blocks into sequential memory locations starting from the lowest address in the memory.

Thus all free blocks that were interspersed with allocated blocks are eliminated, and the free point is reset to the sum of the size of all the allocated blocks.

Thus, one large free block is created at the upper end of the memory and the user request may be filled if there is sufficient storage available. this process is shown in Fig1 on a memory of 1024 words.

When allocated blocks are copied into a lower portion of memory, special care must be taken so that the pointer value remains correct.

For example, the contents of memory location 420 in allocated block 2 of Fig1 might contain the address340. After block 2 is moved to locations 125 through 299, 420 to 220, those content must be changed to 140.

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…

Conclusion:

Memory compaction is the process of shifting all the free memory at one end and used or marked node at one end so that when a request memory is less than the size of free pool memory then we can easily allocate the memory to that block.|What is compaction in memory management|

We have gone through What is compaction in memory management? What is a compaction technique? What is dynamic memory fragmentation? What is storage compaction in a data structure?

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 What is compaction in memory management.

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

Have a great time! Sayonara!

Anurag

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.