liveBook · Manning

Alignment

Memory alignment is the requirement that an object or value be placed at an address satisfying a boundary constraint imposed by its type or hardware.

How 5 Manning books explain it

Modern C, Third Edition

Alignment is the implementation-defined requirement that an object or structure member begin at an address suitable for its type.

How it is used
Explains suitable object addresses in the C memory model and their role in structure layout and pointer conversions.
How deep it goes
Defines type alignment and demonstrates misaligned access with byte-offset pointer casts and a bus-error example.
Examples
Uses padded structure members and a byte-buffer overlay of complex values tested at progressively smaller offsets.
What you can do after
Diagnose misaligned pointer conversions by examining byte offsets and their effects on typed access.

Read how Modern C, Third Edition explains alignment →

Embedded Software with Rust

Memory alignment is the placement of data or code at addresses satisfying the alignment requirements of the target architecture.

How it is used
Establishes alignment as part of the linker-defined memory layout for bare-metal startup.
How deep it goes
Explains 8-byte stack and data-section alignment, associated faults, and the linker directive used for section placement.
Examples
Uses 64-bit stack variables and a linker script aligning .bss before placing its input sections.
What you can do after
Operate/configure a linker script to align .bss and inspect the final memory layout with cargo objdump.

Read how Embedded Software with Rust explains alignment →

Modern C

Alignment is the requirement that an object be stored at an address suitable for its type's access constraints.

How it is used
Constrains pointer-based access to objects within the C memory and object model.
How deep it goes
Defines permissible starting positions, demonstrates a crashing misaligned access, and stops short of broader hardware implementation details.
Examples
Demonstrates a complex double and byte-buffer union tested at offsets 16, 8, 4, 2, and 1.
What you can do after
Diagnose misaligned pointer access and request suitable storage alignment with alignas.

Read how Modern C explains alignment →

Grokking GPU Programming

Memory alignment is the placement of data at an address satisfying the boundary requirements of its type or hardware access.

How it is used
Keeps CUDA memory accesses from needing avoidable extra transactions.
How deep it goes
Explains 128-byte warp starts, pointer offsets, float3 layout, and shared-memory offsets without developing alignment beyond these cases.
Examples
Uses a one-float pointer offset, float3 arrays, and mixed-type shared-memory regions.
What you can do after
Diagnose alignment-related bandwidth losses and choose pointer, padding, or layout fixes.

Read how Grokking GPU Programming explains alignment →

CUDA for LLMs

Memory alignment specifies the address boundary or element multiple to which data is arranged for memory access.

How it is used
Uses alignment to select wider legal memory instructions for moving matrix tiles and to guard vectorized kernel loads.
How deep it goes
Explains element-based GEMM alignment and pointer checks, but does not derive alignment requirements beyond the examples.
Examples
Uses eight-element alignment for 16-bit Hopper operands and an 8-byte int2 carrier for four FP16 values.
What you can do after
Configure vectorized GEMM memory operations by choosing alignment values compatible with operand types and tile dimensions.

Read how CUDA for LLMs explains alignment →

Also covered in

What to know first

Related concepts

Questions about alignment

What is alignment?

Memory alignment is the requirement that an object or value be placed at an address satisfying a boundary constraint imposed by its type or hardware.

Which Manning books explain alignment?

Modern C, Third Edition, Embedded Software with Rust, Modern C, Grokking GPU Programming and CUDA for LLMs.

What should I know before learning alignment?

Manning books that teach alignment usually introduce cache line, data conversion, float4 and memory first.

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.