Basic Allocation

1 / 5

The Free List

block_header_t *free_list_head = NULL;

// Linked list of ALL blocks
// .free flag marks availability
2 / 5
block_header_t *find_first_fit(size_t size) {
    block_header_t *curr = free_list_head;
    while (curr) {
        if (curr->free && curr->size >= size)
            return curr;
        curr = curr->next;
    }
    return NULL;
}
3 / 5

malloc Flow

  1. Check size != 0
  2. Try find_first_fit()
  3. If found: mark used, return payload
  4. Else: request_block() from OS
  5. Return payload or NULL
4 / 5

Why First-Fit?

  • Simple to implement
  • Fast (stops at first match)
  • Reasonable for most workloads
  • Trade-off: fragments at heap start
5 / 5
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.