2014-04-25 19:50

题目:深拷贝和浅拷贝有什么区别?如何应用?

解法:深拷贝传值,浅拷贝传引用。java里对此做了限制,而C++里面用起来更自由。大结构不宜传值,因为拷贝过程效率低。

代码:

 1 // 13.4 What's deep copy and shallow copy? Expain their appications in different cases.
 2 // Answer:
 3 //    deep copy:
 4 //        1. pass by value, often used on small data type, built-in data types.
 5 //        2. data is usually persistent, can be seriailzed directly.
 6 //        3. the data to be deep-copied usually represents objects and entities.
 7 //    shallow copy:
 8 //        1. pass by reference or pointer, often used on large struct or class.
 9 //        2. data is volatile, serialization must be done with the help of persistent data type.
10 //        3. the data to be shallow-copied usually represents relations and mappings between entities.
11 int main()
12 {
13     return 0;
14 }

 

 posted on 2014-04-25 19:58  zhuli19901106  阅读(170)  评论(0编辑  收藏  举报