I was recently asked this question in an interview.
Suppose there is a large library of C programs and each program constantly malloc()
s and free()
s blocks of data. What do you think will happen if there are a million calls to malloc()
and free()
in one run of your program. What will you add to your answer if you have been given a very large memory heap storage?
One thing that may happen is that your memory will be fragmented, especially if you allocate block of different sizes.
Thus, if your memory size is not large, some malloc may fail, even if the total free memory is bigger that requested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With