0
0
Embedded Cprogramming~10 mins

Memory pool (fixed-size block allocator) in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the size of each block in the memory pool.

Embedded C
const size_t block_size = [1];
Drag options to blanks, or click blank then click option'
A128
B64
C256
D512
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a block size too small causes overhead.
Choosing a block size too large wastes memory.
2fill in blank
medium

Complete the code to initialize the memory pool array with the correct total size.

Embedded C
static unsigned char memory_pool[[1]];
Drag options to blanks, or click blank then click option'
Ablock_size * 10
Bblock_size * 40
Cblock_size * 20
Dblock_size * 30
Attempts:
3 left
💡 Hint
Common Mistakes
Using too few blocks limits pool capacity.
Using too many blocks wastes memory.
3fill in blank
hard

Fix the error in the function that allocates a block from the pool by completing the condition to check if a free block is available.

Embedded C
if (free_list_head [1] NULL) {
    // allocate block
}
Drag options to blanks, or click blank then click option'
A<=
B>=
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if free_list_head == NULL causes no allocation.
Using comparison operators like <= or >= is incorrect here.
4fill in blank
hard

Fill both blanks to correctly update the free list head after allocating a block.

Embedded C
allocated_block = free_list_head;
free_list_head = [1];
allocated_block->next = [2];
Drag options to blanks, or click blank then click option'
Afree_list_head->next
BNULL
Callocated_block
Dmemory_pool
Attempts:
3 left
💡 Hint
Common Mistakes
Setting free_list_head to allocated_block causes a loop.
Not setting allocated_block->next to NULL can cause errors.
5fill in blank
hard

Fill all three blanks to correctly add a freed block back to the free list.

Embedded C
void free_block(Block* block) {
    // Optional: clear block data
    memset(block, 0, [3]);
    block->next = [1];
    [2] = block;
}
Drag options to blanks, or click blank then click option'
Afree_list_head
Csizeof(Block)
Dblock
Attempts:
3 left
💡 Hint
Common Mistakes
Not updating free_list_head causes lost free blocks.
Using wrong size in memset causes memory corruption.