liveBook · Manning

Static storage

As explained in Embedded Software with Rust

Memory whose allocation persists for the entire execution of a program.

Static storage holds data allocated for the entire execution of a program. In embedded Rust, its size is fixed at compile time, and its contents persist across function calls. It is useful for lookup tables, configuration constants, and global state. section 7.1.1

The linker determines memory placement, and the reset handler initializes .data and .bss before main runs. These sections hold statically allocated variables in RAM; program code is placed in .text in FLASH. Static memory has deterministic access timing, but it consumes resources for the life of the program. section 7.1.1

Static storage differs from the stack, where function frames come and go as functions are called and return. The heap supports runtime allocation, but in no_std Rust it is not available by default: using it requires alloc, a global allocator, and reserved RAM. section 7.1.1 section 7.5

Fixed capacity is not necessarily static

A local array such as let mut buf: [u8; 32] = [0; 32] provides fixed-capacity storage without a heap. As a local variable, however, it belongs to the function’s stack frame rather than persistent static storage. section 1.3.1 section 7.1.1

Figure 7.1 Memory regions of an embedded Rust program
CH07 F01 Cabanis

Compare static memory with the stack and optional heap in an embedded Rust address space. section 7.1.1

How Embedded Software with Rust covers it

How deep it goes
Explains placement, startup initialization, lifetime, and memory-region trade-offs without showing a static declaration.
Examples
Identifies lookup tables, configuration constants, and global state as uses for static memory.
What it assumes
Assumes familiarity with FLASH and RAM layout, linker scripts, and reset-handler initialization.
What you can do after
Evaluate static storage against stack and heap allocation for persistent data in embedded firmware.
How it connects
Connects static storage with linker scripts, reset handlers, stack memory, heap allocation, and no_std.

Also explained in

Compare how 3 books explain static storage →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.