smart pointer
0 人感兴趣 · 8 次引用
- 最新
- 推荐

C++ 三种智能指针的使用场景
C++98中引入auto_ptr,但是实现有缺陷(使用copy语义转移资源),现已弃用,在实际项目中不应该使用。本文提到的三种智能指针主要指的得是std::unique_ptr、std::shared_ptr和std::weak_ptr。

Rust 从 0 到 1- 智能指针 - 内存泄漏
Rust 的内存安全机制保证使我们难以但并非是不可能的制造出永远不会被清理的内存(即 memory leak,内存泄露)。



Rust 从 0 到 1- 智能指针 -Drop trait
对于智能指针来说第二个重要的 trait 是 Drop,它让我们可以在变量离开其作用域时自定义一些行为。

Rust 从 0 到 1- 智能指针 -Deref trait
实现了 Deref trait 的智能指针可以被看作普通的引用,适用于引用的代码同样也可以作用于智能指针。

Rust 从 0 到 1- 智能指针 -Box<T>
最简单的智能指针,使我们可以将一个值放在堆上而不是栈上,栈上存储的的则是指向堆上数据的指针。