MALLOC() / FREE()

these functions gives developers full control of memory requirements by the program. these are typically used when the size of the data to be processed is not known in advanced.

MALLOC

This function requests and allocates a memory block of a specified size dynamically.

void *malloc(int size);

 * its only parameter provides information about the size of the requested memory and 
   is expressed in bytes;
 * the function returns a pointer of type void * which points to the newly allocated 
   memory block, or is equal to NULL to indicate that the allocation requested could 
   not be granted;
 * the function doesn’t have a clue as to what we want to use the memory for and 
   therefore the result is of type void *; we’ll have to convert it to another 
   usable pointer type;
 * the allocated memory area is not filled (initiated) in any way, so you should 
   expect it to contain garbage.

FREE

Deallocate memory and returns it to the OS. This is required IOT prevent memory leaks.

Last updated