Did you like how we did? Rate your experience!

4.5

satisfied

46 votes

Why would you need to use memory management in C?

All you need to know about memory management in C is: You cannot allocate a shitton of memory on stack, so you need to use malloc You have to guarantee you never go out of bounds, never interpret data as having a different type than it actually has* and never dereference a NULL pointer. You have to guarantee that you will always free memory received from malloc or calloc using the free() function. Note that realloc() will free the original block if it had to move the data, so you only need to free its result. This free() should happen after you no longer need that memory block. There are various techniques to do this. In short you have to always keep track of who is responsible of freeing each allocated memory block. This knowledge is required if you want to make reliable C programs. Its probably not sufficient but goes a long way.

100%
Loading, please wait...