Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT Nachrichten21. September(21.09.2026 um 00:05 Uhr)
YouTube Security VideosŠkoda Peaq im Fahrest: DAS hätten wir nicht erwartet! | CHIP(21.09.2026 um 00:00 Uhr)
Sichere ProgrammierungBackups and other lies(20.09.2026 um 23:42 Uhr)
IT Nachrichten21. September(21.09.2026 um 00:05 Uhr)
YouTube Security VideosŠkoda Peaq im Fahrest: DAS hätten wir nicht erwartet! | CHIP(21.09.2026 um 00:00 Uhr)
Sichere ProgrammierungBackups and other lies(20.09.2026 um 23:42 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

[Advanced Rust] 1.6. Memory Part 4 - Static Memory and the 'static Lifetime Annotation

Reagiere als Erste:r — dein Feedback zählt!

1.6.1. Static Memory

Static memory is actually a collective term. It refers to several closely related regions in the compiled program file. When the program runs, these regions are automatically loaded into memory.

Values in static memory live for the entire duration of the program.

The program’s static memory contains the binary code of the program itself, which is usually mapped as read-only. As the program executes, it walks through the binary instructions in the text segment one by one, and jumps when a function is called.

Static memory holds the memory for variables declared with static, as well as some constant values, such as strings.

1.6.2. The 'static Lifetime Annotation

'static is a special lifetime, and its name comes from static memory. It marks a reference as valid for as long as static memory exists — that is, until the program exits.

The memory for a static variable is allocated when the program starts. By definition, a reference to a value stored in static memory is 'static, because it will not be freed until the program ends. However, a reference with the 'static lifetime annotation does not have to point to static memory.

If a reference with the 'static lifetime annotation does not have to point to static memory, why is this lifetime called 'static? Isn’t it misleading if something has 'static but is not stored in static memory?

  • The name 'static still makes sense because: once you create a reference with the 'static lifetime, for the rest of the program it may as well point to static memory, because the program is allowed to use it for as long as it wants.

In other words, the name 'static may make people think that all references with the 'static lifetime point to static memory — that is, global variables or constants that live for the entire duration of the program. In reality, 'static only means that the reference is valid for the entire lifetime of the program; it does not require the referenced data to be stored in the static section. Put differently, a reference with 'static means “this reference can live forever, and the program can use it at any time”, but it does not force the underlying data to be statically allocated.

When writing Rust code, you will encounter the 'static lifetime annotation more often than static memory itself. 'static often appears in trait bounds for type parameters.

For example, T: 'static means that type T can live for as long as we want — until the program exits — and it also means that T must be owned and self-sufficient. In other words, the type must either not borrow any other (non-static) values or only borrow values that are static. That guarantees the type can live until the end of the program.

1.6.3. The Difference Between const and static

The const keyword declares what follows it as a constant, for example:

const X: i32 = 123;
  • X is declared as a constant.

Constants can be fully evaluated at compile time. During that process, any code that refers to the constant is replaced with the constant’s computed value.

For example:

const X: i32 = 123;
println!("{}", X);

The print operation in this line will be rewritten at compile time as:

println!("{}", 123);

So a constant has no memory or associated storage (because it is not a place). You can think of a constant as a convenient name for a specific value.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten [Advanced Rust] 1.6. Memory Part 4 - Static Memory and the 'static Lifetime Annotation

Thematisch verwandte Begriffe: Advanced, Rust, Memory, Part · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-93957 | A vulnerability has been found in olivier-ls PHP-FTS up to 1.1.3. This a…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick