(计算机)智能指针:一种“像指针一样使用”的对象,用来自动管理动态分配的内存/资源,在合适的时机释放资源,从而减少内存泄漏与悬空指针等问题。常见于 C++(如 std::unique_ptr、std::shared_ptr)。
/smɑːrt ˈpɔɪntər/
A smart pointer can free memory automatically.
智能指针可以自动释放内存。
In modern C++, using a smart pointer helps ensure exception-safe resource management and prevents memory leaks in complex code paths.
在现代 C++ 中,使用智能指针有助于确保异常情况下的资源管理安全,并在复杂的代码路径中防止内存泄漏。
“smart pointer”由 smart(智能的) + pointer(指针)构成,意指这种指针“更聪明”:它不仅保存地址,还把资源生命周期管理封装起来。该概念在 C++ 社区中随着 RAII(资源获取即初始化)思想普及而广泛使用,并在标准库中以 std::unique_ptr、std::shared_ptr 等形式成为主流。