Dynamic Memory Allocation v1 12102017
Dynamic Memory Allocation v1 12102017
Allocation
Definition
The process of allocating
memory at runtime is known
as dynamic memory
allocation.
Library routines known as
"memory management functions"
are used for allocating and
freeing memory during execution
of a program.
These functions are defined
Difference between static and
dynamic memory allocation
Memory Allocation Process
Global variables, static variables
and program instructions get their
memory in permanent storage area
whereas local variables are stored
in a memory area called Stack.
The memory space between these
two region is known as Heap area.
This region is used for dynamic
memory allocation during execution
of the program.
The size of heap keep changing.
Allocating block of Memory
malloc() function is used for allocating
block of memory at runtime. This
function reserves a block of memory of
given size and returns a pointer of type
void. This means that we can assign it to
any type of pointer using typecasting. If
it fails to allocate enough space as
specified, it returns a NULL pointer.
Syntax: