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.
Currently we improved our website User Interface and other contents. Our next update is adding video tutorials on this site so, We create a new YouTube channel, our YouTube channel name is CodeX.
We need some time for make video tutorials (CodeX) so, stay with us and keep supporting and you know already we make a Collaboration with HackIsOn YouTube channel long time ago So, please Subscribe Our Channels