Here we explain dynamic memory management in C. The C programming language provides several functions for memory management and allocation.
Previous | Home | Next |
In c two types of memory management
- Static memory allocation
- Dynamic memory allocation
Static memory allocation
Union is used to group a number of different variables together. In structure number of different variables of different data type stored in different memory places but in union different variable of different data type are store in same place.
Example
{
int rollno;
char name[50];
float salary;
};
{
int rollno;
char name[50];
float salary;
};
Dynamic memory allocation
In dynamic memory management memory will be allocate at runtime. This is also known as heap memory. Some language at the run time have ability to calculate and assign the memory space at run time for an array but c can't have this feature. But in C there is some function which provide the facility to allocate and deallocate the memory. In ,Local Memory, when these function will call memory will allocate automatically and when function will exit memory will deallocated automatically . In dynamic memory allocation ,allocation of memory is explicitly requested for a particular size of block .For deallocation of memory explicitly requested.
The function through which the dynamic memory allocation and deallocation will performed are :
- malloc()
- calloc()
- free()
- realloc()
Previous | Home | Next |