I use heap_2 memory management in my application. All objects are initialised during init, so I use dynamically allocated RAM. I optimized value of configTOTAL_HEAP_SIZE that in the end it holds exact amount of bytes to setup objects.
Let us use following values as complicity:
configTOTAL_HEAP_SIZE = 12 (assume RTOS objects will use 8 bytes (let us say 2 objects and each is 4 bytes) and portBYTE_ALIGNMENT is 4 bytes)
configADJUSTED_HEAP_SIZE = 8 (calculated in memory management with portBYTE_ALIGNMENT )
After init is done value of xFreeBytesRemaining is 0 -> fine because it counts down.
Now I replaced heap_2 handling with heap_1.
With same example from above I see the following Problem during init when the second object (4 bytes) is created in function pvPortMalloc of heap_1 :
/* Check there is enough room left for the allocation. */ if( ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) && ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */
First if condition with the example would lead into:
if( ( (4 + 4) < 8)
So it will not create the object. But in my opinion the heap is allocated correctly with 8 bytes for the two objects and the statement must be less than or equal instead just less than.
Am I missing something?
Thanks in advance!