Chapter 02Allocation and EscapePaid chapter

Value Semantics vs Pointer Semantics — Measured

Determine when value returns are cheaper than pointer returns, where the crossover lies, and how receiver type affects optimization.

Launch paywall

This chapter is part of the paid launch. The preview stays visible so readers can evaluate the exact scope before buying.

Included in

Core, Complete, and Team. Complete also includes the practical exam and free Go-version updates.

Preview

What this chapter teaches

Common belief

Pass by pointer to avoid copying; pointers are faster.

What actually happens

a pointer that escapes costs a heap allocation + GC scan; for small/medium structs the copy is usually cheaper. The right question is does this pointer escape, not is it a pointer.

Mechanisms covered
For structs that fit in a few cache lines (<=128 bytes on amd64), copying is typically cheaper than pointer indirection + GC overhead. The crossover is measurable.
Pointer receivers vs value receivers on methods affect inlining eligibility and escape behavior, not just mutation semantics.
benchcompile
Email-first checkoutUnlock Chapter 02

Unlock Chapter 02 and the rest of the course.

Start with your email, then continue to Lemon Squeezy checkout. Core unlocks the paid chapters, Complete adds the exam and free Go-version updates, and Team gives you 5 seats.

Choose a plan

You'll head to Lemon Squeezy for secure checkout. Global tax is handled there. No subscription. Complete also includes the practical exam and free Go-version updates.

Free chapter
Escape Analysis — The Compiler's Fragile Decision
Understand how the compiler decides between stack and heap allocation, why the decision is fragile, and how to verify it.
Free chapter
Maps — Swiss Tables, Growth, and Permanent Memory
Understand the Go 1.24+ Swiss Table map layout, why maps don't shrink, and how to design for memory reclamation.