Skip to content

Commit

Permalink
Fix Tencent#508 tutorial documentation about move semantics.
Browse files Browse the repository at this point in the history
  • Loading branch information
miloyip committed Jan 19, 2016
1 parent 9515b9c commit bd1be76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ A very special decision during design of RapidJSON is that, assignment of value
~~~~~~~~~~cpp
Value a(123);
Value b(456);
b = a; // a becomes a Null value, b becomes number 123.
a = b; // a becomes number 456, b becomes a Null value.
~~~~~~~~~~
![Assignment with move semantics.](diagram/move1.png)
Expand All @@ -305,7 +305,7 @@ Value o(kObjectType);

![Copy semantics makes a lots of copy operations.](diagram/move2.png)

The object `o` needs to allocate a buffer of same size as contacts, makes a deep clone of it, and then finally contacts is destructed. This will incur a lot of unnecessary allocations/deallocations and memory copying.
The object `o` needs to allocate a buffer of same size as `contacts`, makes a deep clone of it, and then finally `contacts` is destructed. This will incur a lot of unnecessary allocations/deallocations and memory copying.

There are solutions to prevent actual copying these data, such as reference counting and garbage collection(GC).

Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ Value a(kArrayType);
~~~~~~~~~~cpp
Value a(123);
Value b(456);
b = a; // a变成Null,b变成数字123
a = b; // a变成数字456,b变成Null
~~~~~~~~~~
![使用移动语意赋值。](diagram/move1.png)
Expand All @@ -304,7 +304,7 @@ Value o(kObjectType);

![复制语意产生大量的复制操作。](diagram/move2.png)

那个`o` Object需要分配一个和contacts相同大小的缓冲区,对conacts做深度复制,并最终要析构contacts。这样会产生大量无必要的内存分配/释放,以及内存复制。
那个`o` Object需要分配一个和contacts相同大小的缓冲区,`contacts`做深度复制,并最终要析构`contacts`。这样会产生大量无必要的内存分配/释放,以及内存复制。

有一些方案可避免实质地复制这些数据,例如引用计数(reference counting)、垃圾回收(garbage collection, GC)。

Expand Down

0 comments on commit bd1be76

Please sign in to comment.