6. Types of Memory Allocation.
Hello folks!
Welcome to this blog
series. In
the previous blog we have studied classes and its different types. Now in this blog we will see the different types of
memory allocation
Types of
memory allocation :
Memory is required by any
program so as to store the data and process
it.
The memory allocation done by the compiler is of three
different types namely –
1.Static memory allocation
:
This type of memory
allocation is done whenever a variable is declared as static or global. Each
static or global variable defines one block of space, of a fixed size. The
space is allocated when the program is started and is released only after the
program is completely executed.
2.Automatic memory
allocation :
This type of memory allocation is done when a local
variable or function argument is done. The space for automatic variable is
allocated whenever the compounded statement containing the declaration is
entered and the space is allocated until the scope of the respective function
remains.
3.Dynamic memory allocation
:
Dynamic memory allocation is a technique in which
programs determine as they are running where to store some information. You
need dynamic allocation when the amount of memory you need, or how long you
continue to need it, depends on factors that are not known before the program
runs. – gnu.org
Why we need Dynamic memory allocation ?
1. When
we do not know the amount of memory that would be required by the program.
2. When
we do want data structures without any upper limit of memory space.
3. When
we have a fixed size of memory available for running which is not enough to
execute the program correctly.
4. When
you want you to use the concept of structures and linked
list in programming, dynamic memory
allocation is a must, etc.
Space
complexity graph
Time
complexity graph
From the above graphs it is clearly visible that the
memory allocation requirements required by dynamic memory allocation is
certainly small compared to static memory allocation. Hence, in our program we
have tried to use dynamic memory allocation wherever possible which makes the
program more efficient on space complexity rather than time complexity.
Now we have studied the different types of memory
allocation, so in the next blog we will see how to use dynamic memory
allocation in C++
References:
https://stackoverflow.com/questions/322715/when-to-use-linkedlist-over-arraylist-in-java
By-
Ashutosh Bardapurkar (k-05)
Hrishikesh Deshpande (k-16)
Archit Hiwrekar
(k-23)
Chinmay Kapkar (k-33)