Ray's playground

 
上一页 1 2 3 4 5 6 7 8 ··· 56 下一页

2012年3月13日

Item 26: Limiting the number of objects of a class.(More Effective C++)

摘要: Now consider what inline means. Conceptually, it means compilers should replace each call to the function with a copy of the function body, but for non-member functions, it also means something else. It means the functions in question have internal linkage. You don't ordinarily need to worry ... 阅读全文

posted @ 2012-03-13 14:26 Ray Z 阅读(169) 评论(0) 推荐(0) 编辑

Item 25: Virtualizing constructors and non-member functions.(More Effective C++)

摘要: Consider what readComponent does. It creates a new object, either a TextBlock or a Graphic, depending on the data it reads. Because it creates new objects, it acts much like a constructor, but because it can create different types of objects, we call it a virtual constructor. A virtual construc... 阅读全文

posted @ 2012-03-13 10:45 Ray Z 阅读(216) 评论(0) 推荐(0) 编辑

2012年3月12日

Item 24: Understand the costs of virtual functions, multiple inheritance, virtual base classes, and RTTI.

摘要: When a virtual function is called, the code executed must correspond to the dynamic type of the object on which the function is invoked; the type of the pointer or reference to the object is immaterial. How can compilers provide this behavior efficiently? Most implementations use virtual tables... 阅读全文

posted @ 2012-03-12 15:07 Ray Z 阅读(204) 评论(0) 推荐(0) 编辑

Item 23: Consider alternative libraries.(More Effective C++)

摘要: The contrast in performance between iostreams and stdio is just an example, however, it's not the main point. The main point is that different libraries offering similar functionality often feature different performance trade-offs, so once you've identified the bottlenecks in your software ( 阅读全文

posted @ 2012-03-12 14:35 Ray Z 阅读(226) 评论(0) 推荐(0) 编辑

Item 22: Consider using op= instead of stand-alone op.(More Effective C++)

摘要: All this talk of named objects, unnamed objects, and compiler optimizations is interesting, but let us not forget the big picture. The big picture is that assignment versions of operators (such as operator+=) tend to be more efficient than stand-alone versions of those operators (e.g. operator+... 阅读全文

posted @ 2012-03-12 14:23 Ray Z 阅读(245) 评论(0) 推荐(0) 编辑

2012年3月9日

Item 21: Overload to avoid implicit type conversions.(More Effective C++)

摘要: Overloading to avoid temporaries isn't limited to operator functions. For example, in most programs, you'll want to allow a string object everywhere a char* is acceptable, and vice versa. Similarly, if you're using a numerical class like complex (see Item 35), you'll want types like 阅读全文

posted @ 2012-03-09 15:34 Ray Z 阅读(201) 评论(0) 推荐(0) 编辑

Item 20: Facilitate the return value optimization.(More Effective C++)

摘要: The rules for C++ allow compilers to optimize temporary objects out of existence. As a result, if you call operator* in a context like this,Rational a = 10;Rational b(1, 2);Rational c = a * b; // operator* is called here your compilers are allowed to eliminate both the ... 阅读全文

posted @ 2012-03-09 14:08 Ray Z 阅读(190) 评论(0) 推荐(0) 编辑

2012年3月7日

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 ... 阅读全文

posted @ 2012-03-07 13:29 Ray Z 阅读(193) 评论(0) 推荐(0) 编辑

Item 18: Amortize the cost of expected computations.(More Effective C++)

摘要: There is a common theme running through this Item, and that's that greater speed can often be purchased at a cost of increased memory usage. Keeping track of running minima, maxima, and averages requires extra space, but it saves time. Caching results necessitates greater memory usage but reduce 阅读全文

posted @ 2012-03-07 12:59 Ray Z 阅读(194) 评论(0) 推荐(0) 编辑

2012年3月6日

Item 17: Consider using lazy evaluation.(More Effective C++)

摘要: There's nothing about lazy evaluation that's specific to C++. The technique can be applied in any programming language, and several languages — notably APL, some dialects of Lisp, and virtually all dataflow languages — embrace the idea as a fundamental part of the language. Mainstream progra 阅读全文

posted @ 2012-03-06 17:10 Ray Z 阅读(257) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 ··· 56 下一页

导航