79

不要拷贝 | 一根笨茄子

 6 years ago
source link: http://blog.guoyb.com/2018/03/31/dont-copy/?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C++对值语义的支持,导致程序员一不留神就会多出一次“拷贝”的过程。既然选择了C++这种坑多开发效率又低的语言,一定是因为对于性能有比较高的需求(不追求性能,Python、JS、Java选哪个不好?),所以对于无处不在的拷贝,还是尽量避免为好。 对于避免拷贝,一般有以下两种做法: 引用,而不是拷贝引用最初在C++中提出是为了能够更“原生”地处理运算符重载的结果,比如1vec[1] =

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK