ST
StateTrace
Visual Quant & Low-Latency Systems Lab
GitHub
Curriculum/smart-pointers

Smart Pointers

memory model·L1 · combinator·stub
Replacesthe belief that `new` and `delete` are the C++ memory primitives.

`std::unique_ptr` owns exactly one resource (move-only, zero overhead); `std::shared_ptr` is reference-counted (atomic increments, thread-safe refcount but not thread-safe data); `std::weak_ptr` observes without owning (breaks shared_ptr cycles). The choice between them encodes ownership intent in the type system — same idea Rust's borrow checker enforces at compile time.

Prerequisites(root concept)
Bridges
  • reference-counting-vs-tracing-gcshared mechanism
    `std::shared_ptr` is reference counting — deterministic, cycle-prone, atomic-update-cost. Java/Go use tracing GC — non-deterministic, cycle-tolerant, scan-cost. The trade reappears in every language's memory model.
  • arc-mutex-vs-shared-ptrmodel to implementation
    Rust's `Arc<T>` is `std::shared_ptr<T>` with the borrow checker layered on top: `Arc<T>` gives shared ownership, but to *mutate* the inner T you need `Mutex<T>` — at compile time, not runtime. Same refcount mechanism; stronger invariant.
Status

This concept is a node in the curriculum DAG. The full lab — page blocks, done state, references — has not been authored yet. The relations above describe where it sits in the graph.

Author at: content/concepts/smart-pointers/card.ts