Hi Ming-Che Lin,
[quote user="Ming-Che Lin"]In the HeapTrack view, I saw that heapSize was 56 bytes[/quote]
Ok, I have a better understanding of the HeapTrack's 'heapSize' field. heapSizeis actually a cumulative value! For each call to alloc (via HeapTrack), it increments heapSize by the amount being allocated.
Can you check the HeapTrack ROV view again? Looking under the tab called "HeapAllocList"? I'm wondering if when you see 56 bytes (0x38), if there are 2 allocations shown?
I updated the code you sent me and I was able to get the HeapTrack.heapSize equal to 56 bytes using 2 allocation requests of 4 bytes each:
pu32Test = (Uint32 *)Memory_alloc(heap1, sizeof(Uint32), 1, NULL);
pu32Test = (Uint32 *)Memory_alloc(heap1, sizeof(Uint32), 1, NULL);
After stepping over the 2nd Memory_alloc() call, I saw the 56 byte value in ROV for HeapTrack:
And in the HeapAllocList view, I see the two four byte allocations:
Also, regarding differences between the size passed in to allocate, and the size that HeapMem actually uses up ...
HeapMem takes into account the minimum block size and alignment sizes. If you allocate 4 bytes, then a total of 4 bytes + 24 bytes (HeapTrack header size) is actually needed.
But, since the minimum block alignment is 8, the size allocated must be a multiple of 8. 28 is not, and so this size gets rounded up to the nearest multiple of 8, which is 32 bytes.
So, your 4 byte allocation, when used with HeapTrack (due to the extra size needed for the header), will result in a block of size 32 bytes being allocated (since 28 bytes gets rounded up to 32 for HeapMem).
Lastly, you may now be wondering why HeapTrack is not showing a total size (heapSize) of 64 bytes?
This is because this rounding up to the nearest multiple of the block size is something that happens internally within the HeapMem module. HeapTrack doesn't know about that rounding up.
HeapTrack only knows about the 4 bytes requested, plus the 24 byte HeapTrack header size that's needed. And so this is why HeapTrack.heapSize only shows 56 bytes (28 * 2) after the second allocation.
Hope this helps!
Steve