Ray's playground

 

Item 19: Understand the origin of temporary objects.(More Effective C++)

The bottom line is that temporary objects can be costly, so you want to eliminate them whenever you can. More important than this, however, is to train yourself to look for places where temporary objects may be created. Anytime you see a reference-to-const parameter, the possibility exists that a temporary will be created to bind to that parameter. Anytime you see a function returning an object, a temporary will be created (and later destroyed). Learn to look for such constructs, and your insight into the cost of "behind the scenes" compiler actions will markedly improve.

 

posted on 2012-03-07 13:29  Ray Z  阅读(193)  评论(0编辑  收藏  举报

导航