Dear FreeRTOS.
My name is Hoseok who is a newcomer to FreeRTOS. I’m analyzing the Heap2.c
source code for study purposes. I know Heap2
has been superseded by Heap4
, but there is one code snippet I try to understand.
The code snippet below is from Heap2.c
, and its purpose is to add additional bytes for the alignment of BlockLink_t
size and the requested bytes from my understanding. When the requested size is 7 bytes, xAdditionalRequiredSize
should be 8 bytes (BlockLink_t size) + 1 byte (the additional byte needed to align the requested 7 bytes to 8 bytes). This seems fine. However, when the requested size is 8 bytes, xAdditionalRequiredSize
is 8 bytes (BlockLink_t size) + 8 bytes (portBYTE_ALIGNMENT (8)). I initially thought that when the requested size is 8 bytes, xAdditionalRequiredSize
should be 8 bytes (BlockLink_t size) rather than 16 bytes, because the requested size is already aligned to 8 bytes. Could someone help me understand this? Why are 8 bytes added when the requested size is a multiple of 8? Looks like, 8 bytes are wasted or hidden in this case.