Fix #508 tutorial documentation about move semantics.

This commit is contained in:
Milo Yip 2016-01-19 09:59:38 +08:00
parent 9515b9cc94
commit bd1be768f1
2 changed files with 4 additions and 4 deletions

View File

@ -280,7 +280,7 @@ A very special decision during design of RapidJSON is that, assignment of value
~~~~~~~~~~cpp ~~~~~~~~~~cpp
Value a(123); Value a(123);
Value b(456); 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) ![Assignment with move semantics.](diagram/move1.png)
@ -305,7 +305,7 @@ Value o(kObjectType);
![Copy semantics makes a lots of copy operations.](diagram/move2.png) ![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). There are solutions to prevent actual copying these data, such as reference counting and garbage collection(GC).

View File

@ -280,7 +280,7 @@ Value a(kArrayType);
~~~~~~~~~~cpp ~~~~~~~~~~cpp
Value a(123); Value a(123);
Value b(456); Value b(456);
b = a; // a变成Nullb变成数字123 a = b; // a变成数字456b变成Null
~~~~~~~~~~ ~~~~~~~~~~
![使用移动语意赋值。](diagram/move1.png) ![使用移动语意赋值。](diagram/move1.png)
@ -304,7 +304,7 @@ Value o(kObjectType);
![复制语意产生大量的复制操作。](diagram/move2.png) ![复制语意产生大量的复制操作。](diagram/move2.png)
那个`o` Object需要分配一个和contacts相同大小的缓冲区对conacts做深度复制并最终要析构contacts。这样会产生大量无必要的内存分配释放以及内存复制。 那个`o` Object需要分配一个和contacts相同大小的缓冲区`contacts`做深度复制,并最终要析构`contacts`。这样会产生大量无必要的内存分配/释放,以及内存复制。
有一些方案可避免实质地复制这些数据例如引用计数reference counting、垃圾回收garbage collection, GC 有一些方案可避免实质地复制这些数据例如引用计数reference counting、垃圾回收garbage collection, GC