Dynamic memory management is the memory which is given instantly to a program variable or data structure when it is needed. Here we are explaining this dynamic memory management phenomena with reference to the data structure.
There are many occasion while 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. And it is the best help for us when we need a chunk of memory at run time of the program. In the most real-life problem, we need dynamic memory management.
In the multiprocessing computer environment, several programs reside at memory at the same time. a different program has different memory requirements.
For example, one program may require 50k of memory another require 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 the 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 which 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 Fig2. 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 Fig3.
Thus this example of dynamic memory management shows us the necessity to keep the track of available space, to allocate portions of that space when allocation requests are made and to 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 needed a large block of memory.
In the case of any queries, you can write to us at firstname.lastname@example.org 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 feedbacks in the comment section below.
Have a great time! Sayonara!