Tag

weak_ptr

1 views collected around this technical thread.

Deepin Linux
Deepin Linux
Dec 26, 2024 · Fundamentals

Understanding C++ Smart Pointers: Types, Mechanisms, and Best Practices

This article explains how C++ smart pointers—unique_ptr, shared_ptr, weak_ptr and the deprecated auto_ptr—use RAII and reference‑counting to automate memory management, avoid leaks and dangling pointers, and provide guidelines, performance analysis, and practical usage tips for modern C++ development.

CMemory ManagementRAII
0 likes · 36 min read
Understanding C++ Smart Pointers: Types, Mechanisms, and Best Practices
Tencent Cloud Developer
Tencent Cloud Developer
Jan 4, 2022 · Fundamentals

Smart Pointers in C++: Problems Solved, Usage, Best Practices, and Implementation Details

C++11 smart pointers—unique_ptr, shared_ptr, and weak_ptr—replace manual new/delete by providing exclusive, shared, and non‑owning ownership semantics, automatically preventing leaks and dangling references, simplifying multithreaded code, and, when used with best‑practice guidelines, avoid common pitfalls such as double deletions and cyclic dependencies.

CMemory ManagementMultithreading
0 likes · 24 min read
Smart Pointers in C++: Problems Solved, Usage, Best Practices, and Implementation Details