today I need to discuss with you one of the most drawbacks of using Standard heap memory and on of the reasons that we don't use it in most of Embedded Systems it is Fragmentation
what is the fragmentation mean and why fragmentation is affect the run time behavior and performance of our projects ?
of Fragmentation is simple we start our SW with heap as one block heap has a SW control they are some internal functions used by the Malloc,calloc and free functions to handle and control the allocated and deallocated spaces in the heap memory so what
here I will provide the following C example I created 3 continuous memory blocks then I freed all of them so I expected if I create a new block it will start from the heap start address but this is not the case as if created space more than what we created before it will allocated after these blocks this behavior is only achieved if we try to allocate space memory then what we allocated before even if these allocated blocks is freed and the control is return back it the heap controller this is what we called fragmentation that we have enough free memory to allocate but these all some continuous small blocks not merged into one block again
this fragmentation affect the performance as it need slower searching for the sufficient memory to allocate.
also there is some hide fragmentations that may introduced but this may affect if we allocating blocks with small spaces.
but we have the Solution and we can check it .it is implemented in freertos they implement 5 heap memory
but heap 4 & 5 is special implementation to handle this issue you can download it and start to sea it or
I have implemented a simplified version for freertos heap memory you can check it through the following link