Dynamic memory allocations refers to the method of allocating a block of memory and releasing it when the memory is not required at the time of running the program. A block of memory can be used to store values of simple or subscripted variables and a block of memory can be accessed using a pointer. Following are the functions used in dynamic memory allocation, and these functions are available in the header file <alloc.h> ( "alloc.h is a non-standard header file" ) .
malloc() function is used to allocate a single block memory to store values of specific data type. It also assigns the address of the first byte of the allotted space to a pointer.
ptr = (type *)malloc(size);
calloc() function is used to allocate memory in multiple block of same size during the program execution. The space alloted is used to store values of an array or structure.
ptr = (type *)calloc(n, m);
realloc() function is used to modify or re allocated the memory space which is previously allotted.
ptr = realloc(ptr, size);
free() function is used to release the memory space which is allotted using malloc(), calloc() or realloc() function.
A dangling pointer is a pointer that does not point to a valid object and consequently may make a program crash or behave oddly. In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in such a way that memory which is no longer needed is not released. A memory leak may also happen when an object is stored in memory but cannot be accessed by the running code.
We Are Currently Working On Our Android Application Development and We already have two YouTube channels their name is CodeX or NightHawk. CodeX is for programming related videos and NightHawk is for online game streaming so please supporting us and Subscribe to our channels, Thank you