知识卡片
有限堆需要显式处理分配失败
Vec::push等普通接口不以Result报告分配失败,有限堆场景不能据此假定还有恢复机会。可先计算容量并try_reserve,再在已留容量内写入;具体失败类型与稳定性需按接口核对。错误处理中format!也可能分配,不能用会再分配的消息构造证明内存耗尽路径可靠。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 6. Beyond Standard Rust Fallible Allocation · 查看原书依据
Fallible Allocation The earlier sections of this Item considered two different no_std environments: a fully embedded environment with no heap allocation whatsoever (core) and a more generous environment where heap allocation is allowed (core + alloc). However, there are some important environments that fall between these two camps—in particular, those wher
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第6章《Fallible Allocation》(spine10;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch06.html;u171-ch06-006)。
- 结论依据:原文在“Fallible Allocation”附近的定义、例子或代码支撑本卡核心说明:Vec::push等普通接口不以Result报告分配失败,有限堆场景不能据此假定还有恢复机会。边界按已读前提解释;示例未执行。
- 原始内容:Fallible Allocation The earlier sections of this Item considered two different no_std environments: a fully embedded environment with no heap allocation whatsoever (core) and a more generous environment where heap allocation is allowed (core + alloc). However, there are some important environments that fall between these two camps—in particular, those wher