liveBook · Manning

Spatial locality

Spatial locality is the tendency for memory locations near a recently accessed location to be accessed soon afterward.

How 2 Manning books explain it

100 Go Mistakes and How to Avoid Them

Spatial locality is the tendency for memory locations near a recently accessed location to be accessed soon.

How it is used
Guides data-layout choices for cache-efficient loops in CPU-bound applications.
How deep it goes
Explains cache-line fetching, compares data layouts and strides, and quantifies example benchmarks.
Examples
Compares slice-of-structs and struct-of-slices sums, linked-list traversal, and field reordering in Go structs.
What you can do after
Evaluate/understand how layout and access patterns can improve cache-line utilization, then benchmark the alternatives.

Read how 100 Go Mistakes and How to Avoid Them explains spatial locality →

The Coder Cafe

Spatial locality is the tendency for accesses near a recently accessed memory location to occur soon afterward.

How it is used
Explains why arrays can outperform linked lists despite similar or worse theoretical complexity for particular operations.
How deep it goes
Connects locality to cache lines, cache misses, prefetching, and SIMD, but does not develop hardware internals further.
Examples
Contrasts array iteration with contiguous and potentially scattered linked-list allocation, including a 230% slower benchmark.
What you can do after
Evaluate array-versus-linked-list choices using cache behavior and iteration performance, not theoretical time complexity alone.

Read how The Coder Cafe explains spatial locality →

What to know first

Related concepts

Questions about spatial locality

What is spatial locality?

Spatial locality is the tendency for memory locations near a recently accessed location to be accessed soon afterward.

Which Manning books explain spatial locality?

100 Go Mistakes and How to Avoid Them and The Coder Cafe.

What should I know before learning spatial locality?

Manning books that teach spatial locality usually introduce cache line first.

What is spatial locality a kind of?

Spatial locality is a kind of data locality. Data locality is the relationship or constraint between where data is stored and where it is accessed or processed, including spatial proximity and geographic or organizational boundaries.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.