# Beginner Question: pxFirstFreeBlock-\>xBlockSize initialization in prvHeapInit() in heap\_2.c

**URL:** <https://forums.freertos.org/t/beginner-question-pxfirstfreeblock-xblocksize-initialization-in-prvheapinit-in-heap-2-c/25064>\
**Category:** Kernel\
**Tags:** debug\
**Created:** [July 1, 2026, 12:32pm UTC](https://forums.freertos.org/t/beginner-question-pxfirstfreeblock-xblocksize-initialization-in-prvheapinit-in-heap-2-c/25064 "2026-07-01T12:32:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangcoder](https://avatars.discourse-cdn.com/v4/letter/z/c2a13f/32.png) [@zhangcoder](https://forums.freertos.org/u/zhangcoder)\
**Post date:** [July 1, 2026, 12:32pm UTC](https://forums.freertos.org/t/beginner-question-pxfirstfreeblock-xblocksize-initialization-in-prvheapinit-in-heap-2-c/25064/1 "2026-07-01T12:32:30Z")

</div>

Hello,

I’m a beginner learning FreeRTOS Kernel and currently studying the `heap_2.c` memory allocator in detail.

In `prvHeapInit()`, the first free block is initialized as follows:

```c
/* To start with there is a single free block that is sized to take up the
 * entire heap space. */
pxFirstFreeBlock = ( BlockLink_t * ) pucAlignedHeap;
pxFirstFreeBlock->xBlockSize = configADJUSTED_HEAP_SIZE;
pxFirstFreeBlock->pxNextFreeBlock = &xEnd;

```

However, looking at the definition of `BlockLink_t`:

```c
typedef struct A_BLOCK_LINK {
    struct A_BLOCK_LINK * pxNextFreeBlock; /*<< The next free block in the list. */
    size_t xBlockSize; /*<< The size of the free block. */
} BlockLink_t;

```

The comment says `xBlockSize` is “the size of the **free** block”. But since the `BlockLink_t` header is placed at the very beginning of the heap, the actual remaining space **available for user allocation** is smaller than `configADJUSTED_HEAP_SIZE`.

So why pxFirstFreeBlock-\>xBlockSize is set to `configADJUSTED_HEAP_SIZE`?

Thank you in advance for your time and patience! 😁

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [July 2, 2026, 5:15am UTC](https://forums.freertos.org/t/beginner-question-pxfirstfreeblock-xblocksize-initialization-in-prvheapinit-in-heap-2-c/25064/2 "2026-07-02T05:15:56Z")

</div>

This works out because while allocating we add block size to the requested size - [FreeRTOS-Kernel/portable/MemMang/heap\_2.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/portable/MemMang/heap_2.c#L171).
