Chapter 5 Data Structures
- 5.1 Arrays and Slices
- 5.2 Strings and Zero-Copy Conversion
- 5.3 Hash Tables: Principles and Security
- 5.4 Swiss Table and the Go 1.24 Implementation
Slices, strings and maps are the three data structures most used in Go programs. Their syntax is
simple, but each rests on its own runtime layout and growth strategy. When append copies, when
slices share memory, when a string conversion allocates, why a map iterates in random order and
cannot be written concurrently: the answers to all of these follow from layout and implementation,
and need not be memorized as isolated rules.
The chapter has four sections. 5.1 covers the memory layout of arrays and slices, their growth
strategy, and what the compiler does to reduce allocations. 5.2 covers string immutability, UTF-8
and zero-copy conversion. 5.3 covers the general principles of hash tables and hash-flooding
attacks. 5.4 covers the map implementation of Go 1.24, which is based on the Swiss Table.