Chapter 02Allocation and EscapePaid chapter

Value vs Pointer, Measured

Compare value and pointer costs under explicit ownership and call boundaries without assuming a crossover.

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 and Complete. Complete also includes the practical exam and free Go-version updates.

Preview

What this chapter teaches

Common belief

Passing or returning a pointer is cheaper than a value, because it avoids copying the struct. Use pointers on hot paths.

What actually happens

In this benchmark, the escaping pointer variants allocate while the value variants do not. Through 1024 bytes, copying the value remains faster than allocating the pointee. Other call shapes, uses, compilers, and machines can produce different results, so ask "does this pointer escape, and what does this workload measure?

Mechanisms covered
The supplied escaping pointer constructors allocate; a caller-local inlined use can avoid allocation.
Copy cost, allocation, receiver semantics, and compiler decisions must be measured separately.
benchcompile + bench
One-time purchase

Unlock Chapter 02 and the rest of the course.

Core unlocks every paid chapter and lab. Complete also includes the practical exam and future Go-version updates.

Core
$49

Full course access with the complete mechanics curriculum.

All paid chapters unlocked
One-time purchase
Perfect if you want the material only
Complete
$79
Best value

Best-value launch option with the exam and free Go-version course updates.

Everything in Core
Black Belt practical exam
Free Go-version updates

No subscription or account required. Access is tied to the email entered at Stripe Checkout and can be restored by email.

Free chapter
Escape Analysis: The Compiler's Fragile Decision
Distinguish escape diagnostics from measured allocations and explain the role of lifetime and call-site visibility.
Free chapter
Maps: Swiss Tables, Growth, and Permanent Memory
Distinguish map table capacity from referenced payloads and inspect clearing and growth on Go 1.25.