30:用enum代替int常量 当需要一组固定常量的时候,应该使用enum代替int常量,除了对于手机登资源有限的设备应该酌情考虑enum的性能弱势之外. 31:用实例域代替序数 应该给enum添加int域,而不是使用ordinal方法来导出与枚举关联的序数值.(几乎不应使用ordinal方法,除非在编写像EnumMap这样的基于枚举的通用数据结构) //WRONG public enum Fruit{ APPLE, PEAR, ORANGE; public int numberOfFruit(…
1: 在类的头文件中尽量 少 的引用其他头文件,尽量用 @class xxxxxx; 理解: 当你创建了一个 A 类,这个类又 需要具有 B 类的实例, 你可以直接为 A 类添加 B 类类型的 属性, 并引用 B 类的头文件 #import "B.h" 这种方法可行,但是不够优雅,在 编辑一个使用 A 类的文件时候, 不需要知道 B 类的全部细节, 只需要知道有一个 类名叫 B 就好, 所幸有个办法能把这一切情况告诉编辑器 @calss B; 这叫做 '向前声明' 该类 而 A 类的实…
Table of Contents 1 Item 4: Call empty instead of checking size() against zero 2 Item 5: Prefer range member functions to their single-element counterparts 1 Item 4: Call empty instead of checking size() against zero 简而言之,用 container.size() 来检查 conta…
看完,<STL源代码剖析>---stl_deque.h阅读笔记(1)后.再看代码: G++ 2.91.57,cygnus\cygwin-b20\include\g++\stl_deque.h 完整列表 /* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation f…
http://www.agner.org/optimize/#manuals 阅读笔记Optimizing software in C++ 7. The efficiency of different C++ constructs 栈的速度快是因为,总是反复访问同一段地址,如果没有大的数组,肯定实在L1 cahce中. 全局静态区,global,static变量,float constants, string constants, array initializer lists,switch…