C Example: Fixed Block Pool: bitmap marking, allocation and reuse
Implements a fixed pool of eight 32-byte blocks: a used array acts as an occupancy bitmap, alloc scans for the first free slot and returns its index, free clears the mark, and allocating after freeing a middle block reuses that slot. Prints a #/. bitmap after each step to show fragmentation and reuse.
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
alloc -> 0, 1, 2 pool(3/8): # # # . . . . . free b -> ok pool(2/8): # . # . . . . . alloc -> 1 (reused) pool(3/8): # # # . . . . . pool(0/8): . . . . . . . .
🧩 Keep Learning