There are three basic aspect of storage management :
- 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.
- 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.
- 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.
It is the simplest form of allocation i.e an allocation which remain fixed through out the execution.
Properties of static storage management :-
- Storage for all variables allocated in static block.
- Allocation can be done by translator.
- Memory reference can be calculated during run time.
- Subprogram variables uses space even subprogram never called.
- Recursion is not possible.
- All storage known at translator time, and memory reference are calculated.
- Activation records are directly associated with code segment.
- Procedure call and return straight forward.
- Not time or space is expanded for storage management during execution.
- The translator can directly generate values address for all data item.
- In compatible with recursive subprograms or any data structure whose size, is dependent on computed or input data.
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.
- 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.
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.
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.
fig---
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 :-
- 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 :
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.
-> 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.
- 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".
- 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.
- 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.
- Dangling pointer bugs are reduced.
- Double free bugs are reduced : which attempt to free a region that already freed.
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.
INTEGRATED DEVELOPMENT ENVIRONMENT FOR VISUAL BASIC (IDE)
- Java threads and Interrupts in Java programming language
- Abstract classes and Generic function in Java
- Callback functions in Java Programming language
- Constructors in programming language
- Static components and constants concept in programming language
- Data encapsulation in programming language.
- Java threads and Interrupts in Java programming language
2 comments
just information we only provide information for those who need it cara menggugurkan hamil
ReplyA. cara agar cepat hamil setelah selesai haid
B. cara agar cepat hamil
C. cara alami untuk segera mendapat kehamilan
D. makanan dan minuman agar cepat hamil
E. masa subur biar cepat hamil
F. panduan agar cepat hamil
This us one of the best explanation of storage management I cover 3 topic in this
ReplyMcDonalds Wifi Wayport_Access
Thanks sir
Post a Comment