I understand that pucAlignedHeap is getting assigned an aligned memory address from the beginning of the ucHeap array, but I’m confused why the statement uses ucHeap[ portBYTE_ALIGNMENT ] instead of ucHeap[ portBYTE_ALIGNMENT - 1 ].
For example if portBYTE_ALIGNMENT is 8 and portBYTE_ALIGNMENT_MASK is 7 and suppose ucHeap[ portBYTE_ALIGNMENT ] has an address 0x*******F, the aligned address variable, pucAlignedHeap will be getting assigned 0x*******8 which is basically the address of index 1 of the ucHeap array. That means 0th index of the array is not used even in the worst case. I believe there is something off with the way I’m visualising this. Please let me know what I’m missing.
This is not correct. The expression & ucHeap[ portBYTE_ALIGNMENT ] necessarily means ucHeap + portBYTE_ALIGNMENT. So if ucHeap is 0001, ucHeap + portBYTE_ALIGNMENT will be 1001. This, however, still wastes 8 bytes of memory in the case when ucHeap is 8 byte aligned.
Yes you are correct. Initially I thought the first column of the tables in your initial reply was address of the each index of the same ucHeap array. Just now I realized that those values refer to the starting location of ucHeap array at different cases.