rcore-os / rCore-Tutorial-v3

Let's write an OS which can run on RISC-V in Rust from scratch!
https://rcore-os.github.io/rCore-Tutorial-Book-v3/index.html
GNU General Public License v3.0
1.58k stars 452 forks source link

为什么在 frame allocator 里可以使用 Vec 呢 #147

Closed binary-bruce closed 5 months ago

binary-bruce commented 5 months ago

代码:https://github.com/rcore-os/rCore-Tutorial-v3/blob/main/os/src/mm/frame_allocator.rs#L45

我的理解是:物理内存的管理是堆内存管理(动态内存)管理的基础,只有 frame allocator 初始化完成以后才能进行堆内存的初始化,也就可以使用 Vec 和 String 等需要动态内存的数据结构。但 frame_allocator 直接使用 Vec,请问为什么可以这样呢?

StackFrameAllocator 变量(以及里面的字段)应该都在数据段吧。

binary-bruce commented 5 months ago

Sorry。忘记前面已经完成了内核空间的动态内存的初始化了:https://rcore-os.cn/rCore-Tutorial-Book-v3/chapter4/1rust-dynamic-allocation.html