Binding and storage
allocation mechanism
binding
• The time during program organization or processing when this choice
is made is defined as the binding time of that property for that
element. There are multiple varieties of bindings in programming
languages, and a variety of binding times
Types of Binding Times
• Execution Time (Run-Time) − Some bindings are implemented during
program execution. These contain bindings of variables to their
values, and the binding of variables to specific storage areas.
• Translation time (compile-time) − There are three different types of
translation time bindings are as follows −
• Bindings have been chosen by the programmer − In writing a program, the
programmer consciously produces some decisions concerning choices of
variable names, types for variables, program statement structures, etc. that
describe bindings during translation. The language translator creates the
use of these bindings to decide the final structure of the object code.
• Bindings chosen by the translator − Some bindings are selected by the
language translator without a direct programmer requirement. For
example, the relative area of a data object in the storage designated for a
phase is usually managed without knowledge or intervention by the
programmer.
• Bindings chosen by the loader − A program generally includes multiple
subprograms that should be combined into a single executable program.
The translator generally binds variables to addresses within the storage
name for each subprogram. This storage should be assigned actual
addresses within the physical computer that will implement the program.
storage allocation mechanism
• Static Allocation
• It is the simplest allocation scheme in which allocation of data objects
is done at compile time because the size of every data item can be
determined by the compiler.
• Recursive Subprogram and Arrays of adjustable length are not
permitted in a language. In static allocation, the compiler can decide
the amount of storage needed by each data object. Thus, it becomes
easy for a compiler to identify the address of these data in the
activation record.
• FORTRAN uses this kind of storage allocation strategies.
• Advantages
• It is easy to implement.
• It allows type checking during compilation.
• It eliminates the feasibility of running out of memory.
• Disadvantages
• It is incompatible with recursive subprograms.
• It is not possible to use variables whose size has to be determined at
run time.
• The static allocation can be completed if the size of the data object is
called compile time.
Dynamic Allocation (Stack Allocation)
• It can be determined the size of the variables at a run time & hence
local variables can have different storage locations & different values
during various activations.
• It allows recursive subprograms.
• ALGOL language uses this strategy.
• On each execution of a procedure, An Activation Record is generated,
which contains information like Local data, actual parameter, return
value, return address of a procedure. The Activation Record for that
procedure is saved onto the stack.
• If procedure A calls B, and then B calls C, then stack allocation will
be
•
• Advantages
• It supports recursion.
• It creates a data structure for the data item dynamically.
• Advantages
• Memory Addressing can be done using pointers & index Registers.
Heap Storage Allocation
• It enables the allocation of memory in a Non-nested design. Storage
can be allocated & freed arbitrarily from an area known as Heap.
• Heap Allocation is helpful for executing data whose size varies as the
program is running.
• Heap is maintained as a list of free space called free space list.
• Advantages
• A large block of storage can be partitioned into smaller blocks at run
time.
• Disadvantages
• It creates the problem of fragmentation.
Garbage collection
• Garbage collection (GC) is a memory recovery feature built into
programming languages such as C# and Java. A GC-enabled
programming language includes one or more garbage collectors (GC
engines) that automatically free up memory space that has been
allocated to objects no longer needed by the program. The reclaimed
memory space can then be used for future object allocations within
that program.
• In older programming languages, such as C and C++, the developer
must manually delete objects and free up memory. Relying on
manual processes made it easy to introduce bugs into the code, some
of which can have serious consequences.
Disadvantages of Manual GC
• For example, a developer might forget to free up memory after the
program no longer needs it, leading to a memory leak that quickly
consumes all the available RAM.
• Or the developer might free up an object's memory space without
modifying a corresponding pointer, resulting in a dangling pointer
that causes the application to be buggy or even to crash.
Disadvantages of Automatic GC
• Despite its benefits, however, garbage collection can have a negative
impact on performance. Garbage collection is an ongoing process
that requires central processing unit resources, which can affect an
application's general performance or even disrupt its operations