知识卡片
值内嵌与箱式分配
Rust 可以把字段直接嵌在外层值里。((0, 0), (1440, 900)) 直接携带四个整数,构造这个元组无需为每个点单独申请堆内存。需要通过拥有型指针存放值时,Box::new(value) 把值放到堆上,箱子被销毁时释放分配。这样的类型区别让内存布局和释放责任在代码中可见。
关联阅读:[[指针类型决定释放责任]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Fundamental Types 指针类型说明谁管理内存 · 查看原书依据
allocations to a minimum, so values nest by default. The value ((0, 0), (1440, 900)) is stored as four adjacent integers. If you store it
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|指针类型说明谁管理内存,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#pointer-types`
- 结论依据:原文用嵌套元组说明默认内嵌,再用 Box 的构造和销毁说明显式堆分配。
- 原始内容:allocations to a minimum, so values nest by default. The value ((0, 0), (1440, 900)) is stored as four adjacent integers. If you store it