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
[H header bytes][capacity payload bytes]
H = sizeof(block_header_t); capacity excludes the header.
Initialize capacity, free flag, magic, and next=NULL.
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.
Physical candidate = start + H + capacity.
Logical successor = stored next.
A link does not prove physical adjacency.
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.
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.
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.
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.