随笔- 509  文章- 0  评论- 151  阅读- 22万 

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   zhuli19901106  阅读(171)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示