-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from readlnh/master
xlx stage1 summary
- Loading branch information
Showing
1 changed file
with
14 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
title: xlx-2024第一阶段总结报告 | ||
date: 2024-04-26 17:53:16 | ||
tags: | ||
--- | ||
|
||
## 前言 | ||
其实很久之前就一直想完整的过一遍rcore,奈何时间总是不允许。这次正好在写毕业论文,就抽出一点时间。 | ||
|
||
## 过程 | ||
第一阶段的rustlings其实几年前就做过一次。没有太多可讲的点,但是训练营似乎增加了几道之前没接触过的数据结构题,应该属于原创内容,还是比较有趣的。几种数据结构都是比较经典的,但是由于rust语言的特性,诸如链表或是二叉树结构的节点中,子节点都使用了Box智能指针来保存。在一般的传统语言,诸如c/c++,我们会直接保存该指向结构的指针,而rust中,裸指针的操作是不安全的,所以题目中使用Box将节点结构包裹起来。 | ||
这里有一个经典入门问题,为何不在结构中直接保存同样结构的子节点而是使用指针呢?原因在于循环嵌套的结构体会导致编译器无法确定结构体的大小,而指针(当然也包括Box)是固定大小的,从而使得在循环嵌套的情况下,能让编译器在编译期确定结构体的大小。 | ||
对于指针的操作,习题中出于简单考虑,直接在unsafe中使用裸指针操作解决了,实际上,通过使用其它智能指针,合理的设计结构体,是能够完全避免使用unsafe的,这里就不展开说了。希望能够顺利完成所有训练。 | ||
|