SL.
NO Static Memory Allocation Dynamic Memory Allocation
1. When the memory allocation When the memory allocation is
is done at the compile time, done at the execution or run
then it is called static time, then it is called dynamic
memory allocation. memory allocation.
2. In the static memory
In the Dynamic memory
allocation, variables get
allocation, variables get
allocated permanently, till
allocated only if your program
the program executes or
unit gets active.
function call finishes.
3. Static Memory Allocation is Dynamic Memory Allocation is
done before program done during program
execution. execution.
4. It uses stack for managing
It uses heap for managing the
the static allocation of
dynamic allocation of memory
memory
5. It is less efficient It is more efficient
6. In Dynamic Memory
In Static Memory
Allocation, there is memory
Allocation, there is no
re-usability and memory can be
memory re-usability
freed when not required
7. In static memory allocation,
In dynamic memory allocation,
once the memory is
when memory is allocated the
allocated, the memory size
memory size can be changed.
can not change.
8. This allows reusing the
In this memory allocation memory. The user can allocate
scheme, we cannot reuse the more memory when required.
unused memory. Also, the user can release the
memory when the user needs it.
9. Execution is Faster Execution is Slower
10. Example : Array Example: Linked List
Sl. Malloc( ) Calloc( )
N
O
1. malloc() function creates a single calloc() function assigns multiple
block of memory of a specific blocks of memory to a single
size. variable.
2. Malloc() stands for “Memory Calloc() stands for “Contiguous
Allocation” Allocation”
3. It only takes one argument It takes two arguments.
4. It is faster than calloc. It is slower than malloc()
5. malloc() has high time efficiency. calloc() has low time efficiency.
6. It does not initialize the memory
It initializes the memory to zero
to zero
7. Syntax: Syntax:
ptr=(castetype*)malloc(bytesize); ptr=(castetype*)calloc(n,bytesize);