知识卡片

普通读书笔记卡 · 6074.f.6.a

自动析构仍需防止悬垂访问

理解等级:中级

资源自动释放与阻止悬垂引用是两种保障。C++的RAII能关闭局部对象持有的文件,却仍可能留下指向已销毁对象的指针;初次读取看似正常也不能证明有效。Rust安全引用同时受存活检查,unsafe构造的引用也必须由实现者保证有效。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 3. Concepts Evolution of Lifetimes · 查看原书依据

      Evolution of Lifetimes The previous section explained how parameters and local variables are stored on the stack and pointed out that those values are stored only ephemerally. Historically, this allowed for some dangerous footguns: what happens if you hold onto a pointer to one of these ephemeral stack values? Starting back with C, it was perfectly OK to ret

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Evolution of Lifetimes》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u079-ch03-002)。 - 结论依据:原文在“Evolution of Lifetimes”附近的定义、例子或代码支撑本卡核心说明:资源自动释放与阻止悬垂引用是两种保障。边界按已读前提解释;示例未执行。 - 原始内容:Evolution of Lifetimes The previous section explained how parameters and local variables are stored on the stack and pointed out that those values are stored only ephemerally. Historically, this allowed for some dangerous footguns: what happens if you hold onto a pointer to one of these ephemeral stack values? Starting back with C, it was perfectly OK to ret