知识卡片

普通读书笔记卡 · 6074.g.2 · 生成模型:未记录

栈与堆有不同成本

理解等级:中级

栈顶增减适合生命周期嵌套的定长局部数据。堆可按运行时需要申请空间,代价包括分配器簿记和可能的间接访问。String 以定长描述信息管理可变长内容,这个例子强调布局选择与释放责任。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 理解所有权 What Is Ownership? · 查看原书依据

      The heap is less organized: when you put data on the heap, you request a certain amount of space. The memory allocator finds an empty spot in the heap that is big enough, marks it as being in use, and returns a pointer, which is the address of that location.

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第04章 理解所有权(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c04.xhtml`,块 0011) - 结论依据:原文描述堆分配器找空间、返回地址及按地址访问数据。 - 原始内容:The heap is less organized: when you put data on the heap, you request a certain amount of space. The memory allocator finds an empty spot in the heap that is big enough, marks it as being in use, and returns a pointer, which is the address of that location.