Give Each Block a Layout

[H header bytes][capacity payload bytes]

H = sizeof(block_header_t); capacity excludes the header.

Initialize capacity, free flag, magic, and next=NULL.

1 / 7

One Worked Geometry

Header=4096, H=24, capacity=40.

Payload start Block end Total extent
4120 4160 64

block + 1 advances one header; block + H advances H headers.

2 / 7

Physical and Logical Next Differ

Physical candidate = start + H + capacity.

Logical successor = stored next.

A link does not prove physical adjacency.

3 / 7

A Candidate Header Must Fit Completely

H=24, current start=0, capacity=40, arena end=80.

Candidate start=64; only 16 bytes remain → NULL.

Check remaining bytes before constructing an out-of-range pointer.

4 / 7

Alignment Has Three Questions

Is the header aligned? Is the payload aligned? Is the next header aligned?

Base divisible by 16 plus H=24 gives payload alignment of 8, not 16.

The exercise's immediate-header layout is a stated model.

5 / 7

Magic Is a Diagnostic, Not Ownership Proof

Only read the marker in a trusted readable header.

A matching marker can coexist with a corrupted size.

Arbitrary pointer subtraction may already be invalid before a magic check.

6 / 7

Finish the Geometry

H=32, header offset=96, capacity=64.

Calculate the candidate and compare arena ends 224 and 208.

Implement block-header-design; test complete-header bounds and payload round trips.

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