#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 1::2.5 Dynamic Storage Allocation
#columns:Front	Back	Tags
TAOCP §2.5 Dynamic Storage Allocation: what does it cover?	How malloc-style allocators work: first-fit versus best-fit, splitting and merging free blocks, boundary tags for fast coalescing, the buddy system, and simulation results on fragmentation, including Knuth's fifty-percent rule about how many free blocks to expect.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::about
TAOCP §2.5: why does it matter?	Every malloc, every arena and every slab allocator uses these ideas. Understanding fragmentation helps you debug memory blowups in long-running services.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::why
TAOCP §2.5, a common trap: “Alignment.” What's the catch?	Real allocators must return aligned addresses; Knuth's model ignores this.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::trap
TAOCP §2.5, a common trap: “Assuming best-fit always beats first-fit.” What's the catch?	The simulations in the text say otherwise.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::trap
TAOCP §2.5: what traps should you watch for?	<ul><li>Forgetting to merge with both neighbors on free.</li></ul>	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::traps
TAOCP §2.5, exercise 7 (rated 10): what is it asking?	Construct a case where best-fit beats first-fit.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::exercise
TAOCP §2.5, exercise 5 (rated 18, recommended): what is it asking?	Judge a proposed threshold for splitting blocks in first-fit.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::exercise
TAOCP §2.5, exercise 6 (rated 23, recommended): what is it asking?	Next fit: start each search where the last one stopped.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::exercise
TAOCP §2.5, exercise 12 (rated 20, recommended): what is it asking?	Combine boundary tags, the split threshold and next fit in one allocator.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::exercise
TAOCP §2.5, exercise 23 (rated 05): what is it asking?	Compute buddy addresses by flipping one bit.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::exercise
TAOCP §2.5, exercise 26 (rated 21, recommended): what is it asking?	Make the buddy system work when memory is not a power of two.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::exercise
TAOCP §2.5, exercise 36 (rated 20, recommended): what is it asking?	Prove a seating strategy never fails at a lunch counter. A fragmentation puzzle in disguise.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::exercise
TAOCP §2.5, exercise 33 (rated 28, recommended): what is it asking?	Garbage collection with compaction for variable-size nodes. The stretch.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::exercise
TAOCP §2.5: how many exercises, and how are they rated?	44 exercises, rated 00 to HM50.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::exercises
TAOCP §2.5: what should you be comfortable with first?	<ul><li>2.2.3 Linked Allocation</li><li>C malloc/free (clox)</li></ul>	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::prereqs
TAOCP §2.5: how should you work through it?	Implement a tiny first-fit allocator with boundary tags over a static byte array in C, then a buddy allocator. Write a test that does random allocate/free and checks no block overlaps.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.5 cracked.guide::kind::approach
