When I use malloc()
s and free()
s randomly, nested and with different sizes, at some point the memory will be fragmented because these operations leave a large list of small memory areas behind that are non-contiguous and therefore can't be allocated as one bigger piece.
A few questions on this:
When this is done quite often so that memory is forced to be fragmented and then all these memory areas are
free()
d, can I assume these free areas are concatenated back to its original, contiguous size?When I always do a
malloc()
followed byfree()
for the same memory and never nest these calls, is the memory fragmented in this scenario too when allocated/freed sizes are always different?
malloc
followed by afree
and you don't call any library functions that callmalloc
in between , then no fragmentation should occur. – Minima