正常
Pointer Semantics and Weak Reference Design
Pointers are everywhere in C++, yet not every pointer owns the object it points to. A raw T* can be owning or non-owning, T& expresses a borrow but can never be null, and std::weak_ptr solves the weak-reference problem under shared ownership — but what if you don't manage your objects with shared_ptr? How is Chromium's WeakPtr designed? And why does T* + raw Flag* look like a WeakPtr while not actually being one?
In this series we hand-roll all kinds of non-owning pointer types from scratch, pinning down their semantic boundaries, safety conditions, and engineering trade-offs as we build.
Chapter Contents
Non-Owning Pointers: A Panorama from T* to Borrowed to ObserverPtrWeakPtr Anti-Pattern: The Fatal Trap of T* + raw Flag*SimpleWeakPtr: A Safety Improvement over T* + shared_ptr<Flag>Chrome-like WeakPtr: Reference-Counted Control Block and WeakPtrFactorystd::weak_ptr Compared: Async Callbacks in PracticeSeries Wrap-Up: Cross-Thread Safety, Performance Trade-offs, and Design Principles