First time using malloc installs heap?

I had a bug, which I have now fixed, but which I need to explain in the report.

I am working on an embedded device running FreeRTOS that does its own heap memory management. FreeRTOS has its own version of malloc (), pvPortMalloc () which I was not aware of and used, fixed the memory issues I had.

My question is about the size of the memory overflow caused by malloc (), the data size was only 8 bytes, however the size of the overflow was significant, kilobytes if not more. My guess is the first and only use of malloc in this application that created a second heap in competition with the FreeRTOS heap, at least a few kb is the size.

Can someone confirm this or give a better explanation. Pointers to more information or links were highly appreciated.


source to share

1 answer

This is a common feature of many malloc implementations to request more memory from the system than is needed for a single request. For example glibc ptmalloc has the following:

#define MINIMUM_MORECORE_SIZE  (64 * 1024)


This serves as a lower bound on the amount of memory (in bytes) to request from the OS (through sbrk()

) at one time. Thus, you would expect to see one tiny 64K "in use" allocation result.

One of the reasons for doing this is to reduce system calls; the other might be to reduce fragmentation.



All Articles