Reserve a Region Before Allocating Blocks

sbrk-basics tracks raw bytes and growth attempts.

It does not yet align payloads, add headers, reuse blocks, or free them.

1 / 6

Old Break and New Boundary

Start 4096; request 24 successfully.

  • Return 4096.
  • New break 4120.
  • New region [4096,4120).

The end pointer is outside the writable bytes.

2 / 6

Separate Attempts From Acquired Bytes

Requests: 24 succeeds, 8 succeeds, 64 fails.

Successful bytes Growth attempts
32 3

Zero and sbrk(0) queries do not count as growth attempts.

3 / 6

Validate Before Converting or Adding

Reject before calling sbrk when:

  • size is zero;
  • size exceeds INTPTR_MAX;
  • size exceeds SIZE_MAX - total_requested.

Recognize (void *)-1 before updating successful bytes.

4 / 6

Reset Does Not Shrink

heap_init() resets accounting at the current boundary.

Freeing interior B cannot lower the break through later live C.

Raw one-byte requests do not imply aligned objects.

5 / 6

Predict, Implement, Explain

Start 1000; request 7 successfully, reject an unrepresentable increment, request 9 successfully.

Predict both pointers, break, byte total, and attempt count.

Then implement sbrk-basics and trace failure without exhausting real memory.

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