One Ownership Model, Four APIs

Malloc claims a free block. Free makes it reusable. Realloc transfers ownership after success. Calloc clears the requested bytes after allocation.

1 / 5

Predict the trace

A:32 live, B:64 live. Free A, then request 20.

A is reused and retains capacity 32. B remains untouched.

2 / 5

Growth failure

A is live; request SIZE_MAX.

Reject before heap mutation. Return NULL; A remains used and its bytes unchanged.

A zero-size custom realloc instead deliberately frees A.

3 / 5

Coalescing extension

Adjacent free payloads 32 and 64, header H.

Merged capacity: 32 + H + 64.

Check physical adjacency; list neighbors may have padding or other storage between them.

4 / 5

Exit check

Does calloc need to clear a reused block?

Yes: free changes eligibility, not contents. Zero all requested bytes even if the capacity is larger.

The capstone requires reuse; splitting and coalescing are optional extensions.

5 / 5
←/→ or click edges to navigate · ? help · N notes · F fullscreen