Memory wasted in pvPortMallocGeneric

Description

The ee8ffed465776db593c1c1a25a9abbcdc62d728d patch added support to only use 4-bytes alignment for heap allocations. The patch contains a bug that increase the allocation size by 4 bytes, if the requested size already is 4-bytes aligned, but not 8-bytes aligned.

For heap allocation we have alignment == 4 and portBYTE_ALIGNMENT == 8.

One example where we unnecessarily increase the allocation size is if xWantedSize == 12. In this case the if statement is true and we increment xWantedSize with ( alignment - ( xWantedSize & mask ) ) => (8 - (12 & 7)) => 4 although the size is already 4-bytes aligned

Environment

None

Activity

Show:
Stefan Karlsson
July 17, 2015, 3:02 PM

Fixing this gives a small decrease in memory usage on the CC3D.

SystemStats.HeapRemaining:

  • Before fix: 1216 bytes

  • After fix: 1408 bytes

Stefan Karlsson
July 19, 2015, 12:50 PM

Closing this since PR has been merged to next.

Assignee

Stefan Karlsson

Reporter

Stefan Karlsson

Labels

None

Fix versions

Affects versions

Priority

Configure