Featured Posts

Storage Management Phases

There are three basic aspect of storage management :
  1. Initial allocation :  At the start of execution every storage is either allocated or freed.  If free initially then that location may be dynamically used by the subprogram.  So, a mechanism is needed for keeping track that when to used that free memory location.
  2. Recovery :  A storage used by some elements is freed up after the execution.  To make that location available must have to be recovered by the storage manager.  Recovery may be very simple, as in the re-positioning of a stack pointer, or very complex, as in garbage collection.
  3. Compaction and reuse :  Storage required may be immediately ready for reuse compaction may be necessary to construct large blocks of free storage from small pieces.  Reuse of storage ordinarily involves the same mechanisms as initial allocation.
# Static Storage Management :-
          It is the simplest form of allocation i.e an allocation which remain fixed through out the execution.
Properties of static storage management :-
  1. Storage for all variables allocated in static block.
  2. Allocation can be done by translator.
  3. Memory reference can be calculated during run time.
  4. Subprogram variables uses space even subprogram never called.
  5. Recursion is not possible.
  6. All storage known at translator time, and memory reference are calculated.
  7. Activation records are directly associated with code segment.
  8. Procedure call and return straight forward.
 # Advantage :-
  • Not time or space is expanded for storage management during execution.
  • The translator can directly generate values address for all data item.
 # Disadvantage :-
  • In compatible with recursive subprograms or any data structure whose size, is dependent on computed or input data.
 # Stack Based Storage Management :-

                Stacks are used to hold information about procedures calling and arrange them in such a manner that when a procedure terminate, it will move to the context of the main program.  They follow a run time protocol between caller and callee to save arrangements and return value on the stack.  They also support recursive subprogram and that is a system controlled storage management.
              Some language use stack to create local referencing environment  which will vanish on the exit of the procedure.
A stack has two basic operations : Push and Pop.
Push : adds a node to the top.
Pop : Removes and return current top (LIFO).
        The stack is implemented with a little more than just push and pop.  The length of a stack can also returned as a parameter top[1] can return the top element without removing it.

# Advantages :
  • As data is added and removed by LIFO.  So, allocation is simpler and faster.
  • Memory on the stack is automatically reclaimed with the function exits.
 # Disadvantage :-
  • A stack can be very small and is dynamically grow and shrink in size.  So, sometimes allocating more memory on the stack than available can result in crash due to overflow.
 # Heap Storage Management :-

           A heap is a block of storage with in which pieces are allocated and freed in any manner.  Here the problems of storage allocation, recovery, compaction and reuse may be serve.  The heap storage management is a collection of techniques, which needs to be run side by side.
           There are two types of dynamic storage which needs to be co-exist in memory.  They both grow and shrink through out program execution.

# Properties of Heap Storage Management :-
  • Generally used as storage for object with unrestricted lifetime.
  • Maintains a list of free space ( free list ).
  • An allocation memory allocation finds space according to any of the method and mark it as used : 1. best fit 2. worst fit 3. first fit.
  • On deallocation-memory manager marks it as free.
  • Memory fragmentation - the memory is divided in small blocks during lifetime because for eg. when a block is allocated memory to then the size may be small as compared to free block that may again break.
  • Garbage collection.
         The allocation and deallocation can be done at arbitrary points.  Heap storage management techniques is divided into two categories depending on whether the elements allocated are always of the same fixed size or of variable size.
# Heap Storage Management For Fixed Size Elements :-

           In fixed size elements all the elements stored are of same size thus allocation can be done easily.  Let  suppose an element of heap is 'N' words long and in total there are 'K' elements.  Thus size of heap is K*N words long.  If allocation is done then generally is done on the basis of first fit.  Initially all the 'K' elements are linked together in the form of a free space list.  The free element will point to the next free element and allocated element is removed from the list.
        And when we free the allocated storage it will take that as a part of the free list.
        In the free space of identification and of freed storage elements in fixed sized heap, many problems occurs and they are :-
  1. Explicit return by programmer or system :  This is the simplest method, when an element available for reuse, it will be identified as free and return to free space list but there are some problems in that :
   i). Dangling reference :-  It occurs when an object is deleted or deallocated, without being modified the value of the pointers.  Such that the pointer is still pointing towards the deallocated memory references.  This cause unpredictable results because that memory space is now allocated to any other element such that the pointer can now modify the value.

  ii) Garbage :-  It is opposite to dangling reference, if the access path is destroyed with the object still allocated to the memory and storage is recovered but it is not a part of the free list and not available for reuse.  If garbage accumulate, available storage is reduced until the program halts due to lack of free space.

# Reference counts :-
         It is an easy way to recognize garbage and makes its space reusable for new cells.  In that, each heap cell is argumented by count field, which record the total number of pointer which points to the particular cell.  when an item is initially allocated, the reference count is set to 1, and every time a new pointer points to the object the counter is increased by 1 and each time, a pointer is destroyed the reference counts is decreased by 1.  If counter sets to 0, we can reuse the cell by placing it on a free list and non-zero reference counts indicate that the structure still accessible and a free command cannot access that.
# Advantage :-
-> Conceptually simple.
-> Immediate reclamation of storage.
# Disadvantage :-
-> Extra space is required to store reference counter
-> Can't collect cyclic garbage
-> Decrease in execution efficiency because testing, incrementing and decrementing access continuously through out execution.

Garbage collection :-   

        The basic principle of how a garbage collector works are :
  • determine what data objects in a program will not be accessed in future.
  • and after determination, will reclaim the resources used by those objects.
      We sat that dangling reference is bigger problem of two, they both are associated with the freeing of storage.  In dangling reference, the memory is freed too early and in garbage memory is freed too late and it is better to have garbage in a program rather than dangling reference.  So, we avoid dangling and allow garbage to be created.  Which creates problem when the heap is full so garbage collection occurs once heap is full and process is called rarely.  So it is allowable for the procedure to be fairly costly.  Two stages are involved.

  1.  Mark :-  Initially the garbage collection bit is set to 1 and elements are either active or garbage and after checking it will change the garbage collection bit of active element to 'O'.  Thus every garbage is now marked as "on".
  2.  Sweep :-  After a sequential scan, the garbage collection bit is checked and the elements whose garbage collection bit is "on" has been added to the free space list.
          The marking procedure has to check all outside pointers and pointers from active members that means they are not garbage.  For marking we have three critical assumption :-
  • Any active element must be reachable by a chain of pointers beginning outside the heap.
  • It must be possible to identify every pointer outside the heap that points to an element inside the heap.
  • It must be possible to identify within any active heap element the fields that contain pointers to other heap elements.
 #  Advantages :-
  1. Dangling pointer bugs are reduced.
  2. Double free bugs are reduced : which attempt to free a region that already freed.
#  Disadvantage :-  It adds overhead that can affect program performance.  Thus more CPU time is used to free memory space.

Storage Management in Programming Language
Programming Languages Concepts 
Subprogram Sequence Control in Programming language. 
Structured Sequence Control in Programmig language 
Sequence Control with in Statements 
Implicit and Explicit sequence Control 
Difference between C language and C++ language.
  1. Java threads and Interrupts in Java programming language
  2. Abstract classes and Generic function in Java
  3. Callback functions in Java Programming language
  4. Constructors in programming language
  5. Static components and constants concept in programming language
  6. Data encapsulation in programming language.
  7. Java threads and Interrupts in Java programming language


Post a Comment


www.posthatke.com. Powered by Blogger.
Copyright © www.posthatke.com | Blogger Templates | Designed By posthatke.com