知识卡片

普通读书笔记卡 · 6074.h.1.c

跨界指针必须说明访问与拥有契约

理解等级:中级

指针跨FFI只传地址,不自动携带Rust的寿命、别名或锁约束。必须约定对方能否保留、修改、跨线程使用与释放,并让分配和释放使用匹配机制。C代码即使收到const指针,也不自动被Rust借用检查保护;安全封装需要验证双方真实行为。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 6. Beyond Standard Rust Lifetimes · 查看原书依据

      Lifetimes Most data structures are too big to fit in a register and so have to be held in memory instead. That in turn means that access to the data is performed via the location of that memory. In C terms, this means a pointer: a number that encodes a memory address—with no other semantics attached (Item 8). In Rust, a location in memory is generally repres

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第6章《Lifetimes》(spine10;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch06.html;u179-ch06-013)。 - 结论依据:原文在“Lifetimes”附近的定义、例子或代码支撑本卡核心说明:指针跨FFI只传地址,不自动携带Rust的寿命、别名或锁约束。边界按已读前提解释;示例未执行。 - 原始内容:Lifetimes Most data structures are too big to fit in a register and so have to be held in memory instead. That in turn means that access to the data is performed via the location of that memory. In C terms, this means a pointer: a number that encodes a memory address—with no other semantics attached (Item 8). In Rust, a location in memory is generally repres