知识卡片
持久状态可用复制换接口简化
把消息值从借用切片改为拥有Vec,可让服务器保留配置而不牵连每次接收缓冲的借用。它付出分配与复制成本,换来输入可释放或重用的清楚边界。示例长度字段为u8,单条值最多255字节;是否值得零复制应按实际负载测量,而不是默认拒绝复制。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 3. Concepts Data Structures and Allocation · 查看原书依据
value: Vec<u8>, // owned heap data } and the get_next_tlv() code is correspondingly tweaked to include an additional call to .to_vec(): // ... let tlv = Tlv { type_code, // Copy the relevant chunk of data to the heap. // The length field in the TLV is a single `u8`, // so this copies at most 256 bytes. value: input[2..2 + len].to_vec(), }; then the server co
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《Data Structures and Allocation》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u110-ch03-050)。
- 结论依据:原文在“value: Vec<u8>”附近的定义、例子或代码支撑本卡核心说明:把消息值从借用切片改为拥有Vec,可让服务器保留配置而不牵连每次接收缓冲的借用。边界按已读前提解释;示例未执行。
- 原始内容:value: Vec<u8>, // owned heap data } and the get_next_tlv() code is correspondingly tweaked to include an additional call to .to_vec(): // ... let tlv = Tlv { type_code, // Copy the relevant chunk of data to the heap. // The length field in the TLV is a single `u8`, // so this copies at most 256 bytes. value: input[2..2 + len].to_vec(), }; then the server co