We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inside-rust-std-library/02-内存.md
Lines 734 to 744 in 432c4e6
该指针可能指向一个正常的变量,所以不能认为指向的内存是未初始化的。
这个dangling函数就是把指定类型的对齐值作为一个usize,再把这个usize用std::mem::transmute转为一个指针,所以是不是不能认为它指向一个可能的变量,因为这个指针的值本身还没有完成初始化。 所以在这个基础上,去说它指向的内存是否初始化,没有意义。
std::mem::transmute
dangling实际表示NonNull<T>无意义,与NonNull<T>的本意有些违背,因为这个语义可以用None来实现。
NonNull<T>
既然dangling返回一个NonNull,那么这个指针绝对不是==0的
比如:
let ptr = unsafe { NonNull::<u32>::new_unchecked(std::ptr::null_mut()) }; let op = Some(ptr); assert_eq!(op.is_none(), true);
The text was updated successfully, but these errors were encountered:
No branches or pull requests
inside-rust-std-library/02-内存.md
Lines 734 to 744 in 432c4e6
这个dangling函数就是把指定类型的对齐值作为一个usize,再把这个usize用
std::mem::transmute
转为一个指针,所以是不是不能认为它指向一个可能的变量,因为这个指针的值本身还没有完成初始化。 所以在这个基础上,去说它指向的内存是否初始化,没有意义。既然dangling返回一个NonNull,那么这个指针绝对不是==0的
比如:
The text was updated successfully, but these errors were encountered: