知识卡片

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

栈帧复用使局部地址失效

理解等级:中级

栈帧可理解为一次函数调用的局部状态,返回后该区域可被下一次调用复用。因此保存局部对象地址不能使对象在返回后继续有效。真实参数可能放寄存器,函数也可能内联;栈帧模型解释存活风险,不是固定机器布局或地址保证。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 3. Concepts Introduction to the Stack · 查看原书依据

      stack frame is added to the stack, beyond where the stack frame for the calling function ends, and the CPU normally updates a register—the stack pointer—to point to the new stack frame. When the inner function f() returns, the stack pointer is reset to where it was before the call, which will be the caller’s stack frame, intact and unmodified. If the caller

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Introduction to the Stack》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u078-ch03-001)。 - 结论依据:原文在“stack frame”附近的定义、例子或代码支撑本卡核心说明:栈帧可理解为一次函数调用的局部状态,返回后该区域可被下一次调用复用。边界按已读前提解释;示例未执行。 - 原始内容:stack frame is added to the stack, beyond where the stack frame for the calling function ends, and the CPU normally updates a register—the stack pointer—to point to the new stack frame. When the inner function f() returns, the stack pointer is reset to where it was before the call, which will be the caller’s stack frame, intact and unmodified. If the caller