Dynamic storage allocation techniques in Compiler design
6,550 views
11 slides
Oct 12, 2020
Slide 1 of 11
1
2
3
4
5
6
7
8
9
10
11
About This Presentation
Related on Dynamic storage allocation techniques in Compiler design. Two methods are explicit and implicit with examples. Prepared by SVIT student.
Size: 3.36 MB
Language: en
Added: Oct 12, 2020
Slides: 11 pages
Slide Content
CD Dynamic Storage Allocation Techniques Kunjan Shah 170410107103 LY CE 2 Batch C
Dynamic Memory Allocation Those cases where the input isn’t known beforehand, we suffer in terms of inefficient storage use and lack or excess of slots to enter data (given an array or similar data structures to store entries). So, we define Dynamic Memory Allocation. Memory is allocated during the execution of the program. It leads to better memory utilization i.e. there is no wastage of memory. Allocated only when program unit is active. This dynamic memory allocation is generally used for linked list. It uses heap for managing the dynamic allocation of memory.
Dynamic Memory Allocation Two techniques are used in DMA: Explicit allocation Implicit allocation Explicit allocation is the kind of memory allocation that can be done with the help of some procedures. For example – In PASCAL the memory allocation is done using new function and deallocation is done using dispose function. Implicit allocation is a kind of allocation that can be done automatically by the compiler using run time support packages.
Explicit allocation The explicit allocation can be done for fixed size and variable sized blocks. Explicit Allocation for Fixed Size Blocks This is the simplest technique of explicit allocation in which the size of the block for which memory is allocated is fixed. In this technique a free list is used. Free list is a set of free blocks. This observed when we want to allocate memory. If some memory is de-allocated then the free list gets added. The blocks are linked to each other in a list structure. The memory allocation can be done by pointing previous node to the newly allocated block. Memory deallocation can be done by dereferencing the pervious link. Pointer which points to first block is called Available. Memory allocation and deallocation is done by using heap memory. Advantage is that there is no space overhead.
Explicit allocation
Explicit allocation Explicit Allocation for Variable Size Blocks Due to frequent memory allocation and deallocation the heap memory becomes fragmented. That means heap may consist of some blocks that are free and some that are allocated. In short, not proper memory utilization. Suppose a list of 7 blocks get allocated and 2, 4 and 6 is deallocated then fragmentation occurs. Thus we get variable sized blocks that are available free.
Explicit allocation Explicit Allocation for Variable Size Blocks For allocating variable sized blocks some strategies such as first fit, worst fit and best fit are used. When a block of size S is allocated and if we search for the free block in the heap and the first available free block whose size > S is used then it is called first fit. Sometimes all free blocks are collected together to form a larger free block. This ultimately avoids the problem of fragmentation.
Implicit allocation Performed using user program and runtime packages. The run time package is required to know when the storage block is not in use.
Implicit allocation Two problems mainly: Recognizing block boundaries. If the block size is fixed then user data can be easily accessible. To determine which block is in use. Two approaches is used for implicit allocation: Reference count - It is a special counter used during implicit memory allocation. If any block is referred by some another block then its reference count incremented by one. That also means if the reference count of particular block drops down to 0 then, that means that block isn’t referenced one and hence it can be de-allocated.
Implicit allocation Two approaches is used for implicit allocation: 2 . Marking techniques – This an alternative approach to determine whether the block is in use or not. In this method, the user program is suspended temporarily and pointers are used to mark the blocks that are in use. Sometime bitmaps are used. Bitmaps are used to mark the blocks which are in use. A bit-table stores all the bits. This table indicates the blocks which are in use currently. These pointers are then placed in the heap memory. Again we go through heap memory and mark those blocks which are unused. Thus using marking technique it is possible to keep track of the blocks that are in use. By marking we can determine, which blocks are used and which are not .