知识卡片
分配能力与操作系统服务分开
no_std环境若有可用分配器,可显式引入alloc使用Vec、String、Box与树形集合,它们与std重导出类型相同。OS相关网络、文件与标准同步能力则不能由alloc替代。Arc还受目标原子能力限制;不能因名字在alloc中就假定每个裸机目标都支持。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 6. Beyond Standard Rust alloc · 查看原书依据
alloc library. As with core, these alloc variants are actually the same types under the covers. For example, the real name of std::vec::Vec is actually alloc::vec::Vec. A no_std Rust crate needs to explicitly opt in to the use of alloc, by adding an extern crate alloc; declaration to src/lib.rs:3 //! My `no_std` compatible crate. #![no_std] // Requires `allo
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第6章《alloc》(spine10;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch06.html;u169-ch06-003)。
- 结论依据:原文在“alloc library”附近的定义、例子或代码支撑本卡核心说明:no_std环境若有可用分配器,可显式引入alloc使用Vec、String、Box与树形集合,它们与std重导出类型相同。边界按已读前提解释;示例未执行。
- 原始内容:alloc library. As with core, these alloc variants are actually the same types under the covers. For example, the real name of std::vec::Vec is actually alloc::vec::Vec. A no_std Rust crate needs to explicitly opt in to the use of alloc, by adding an extern crate alloc; declaration to src/lib.rs:3 //! My `no_std` compatible crate. #![no_std] // Requires `allo