1. byte boundary alignment improves read/write speed
2. the constructor tries its best to use the initialization list (otherwise, the object type will have an initial value constructed by default)
3. Try to use the front ++, because the back ++ will generate a temporary object.
4. Do not use struct function return values
Struct;
A = F (1 );
A temporary object is generated.
Struct a = F (1); this will not generate a temporary object
5. Avoid constructing with a value (you can add explicit it before the constructor to avoid-implicit conversion is not allowed)
STD: String S = "hello"; the actual operation of this sentence is S = STD: String temp ("hello ");
A temporary object is generated. The correct method is STD: String S ("hello"). You can call the constructor directly.
6. Simplified processing in the loop (1) repeated operations must be put out of the loop (2) the busiest loop should be put in it)
7. Avoid recursion as much as possible. It is best to convert it into a loop (must be used, and a definite exit condition is required)
8. Use less floating-point numbers (convert * 10, * 100 to an integer)
9. Pass pointer or reference using function parameters (complex structure) ---- avoid copying Structures
10. Do not format I/O using strings in the Key Path (string formatting is slow)
11. do not apply for memory at Will (if new is available, do not use new). Use the stack memory.
The string value is a dynamic size. When the space is insufficient, the new memory is added. The C language string is much faster than the C ++ string value.
12. Use sizeof (computed during compilation), instead of strlen (computed during runtime)
Char A [10] = "hello ";
Sizeof ();
Strlen ();
Result: 10 5
13. frequent application of heap space smaller than kb will lead to memory expansion
Because small memory blocks are directly implemented through the low pointer of the Offset heap, only the latest memory is released will the previous memory be released. Continuous application will lead to expansion.
14. Use STL containers with caution-Misuse of Small memory blocks in the heap Area
15. Select the appropriate container for the vector deque list
STD: vector is a continuous space. The memory block needs to be moved for addition and deletion, and the memory needs to be re-allocated.
Deque concatenates multiple fixed-length heap arrays.
STD: List Bidirectional Ring linked list
Map
Hash table
16. Multithreading
Mutex lock
Read/write lock
Conditional lock
Spin lock
Barrier lock
17. Efficient I/O kqueue epoll