mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2024-11-14 04:41:49 +08:00
update ch04-01 close #682
This commit is contained in:
parent
e14942a769
commit
fe175e6e15
@ -143,15 +143,17 @@ style="width: 50%;" />
|
||||
|
||||
当我们将 `s1` 赋值给 `s2`,`String` 的数据被复制了,这意味着我们从栈上拷贝了它的指针、长度和容量。我们并没有复制指针指向的堆上数据。换句话说,内存中数据的表现如图 4-2 所示。
|
||||
|
||||
<img alt="s1 and s2 pointing to the same value" src="img/trpl04-02.svg" class="center" style="width: 50%;" />
|
||||
<img alt="Three tables: tables s1 and s2 representing those strings on the
|
||||
stack, respectively, and both pointing to the same string data on the heap."
|
||||
src="img/trpl04-02.svg" class="center" style="width: 50%;" />
|
||||
|
||||
<span class="caption">图 4-2:变量 `s2` 的内存表现,它有一份 `s1` 指针、长度和容量的拷贝</span>
|
||||
|
||||
这个表现形式看起来 **并不像** 图 4-3 中的那样,如果 Rust 也拷贝了堆上的数据,那么内存看起来就是这样的。如果 Rust 这么做了,那么操作 `s2 = s1` 在堆上数据比较大的时候会对运行时性能造成非常大的影响。
|
||||
|
||||
<img alt="Three tables: tables s1 and s2 representing those strings on the
|
||||
stack, respectively, and both pointing to the same string data on the heap."
|
||||
src="img/trpl04-02.svg" class="center" style="width: 50%;" />
|
||||
<img alt="Four tables: two tables representing the stack data for s1 and s2,
|
||||
and each points to its own copy of string data on the heap."
|
||||
src="img/trpl04-03.svg" class="center" style="width: 50%;" />
|
||||
|
||||
<span class="caption">图 4-3:另一个 `s2 = s1` 时可能的内存表现,如果 Rust 同时也拷贝了堆上的数据的话</span>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user