1. The alignment principle. For example, 64-bit bus, each address read 8B. Pay attention to the variable address when programming, and consume the least number of addresses of the bus. Heap memory request, the system is strictly aligned according to the principle of alignment, so use time also try not to cross the addressing boundary.
2. When needed, the code can be copied for efficiency, although the code volume is increased, but it is worthwhile. Especially for loops, if the number of times is less, it is no harm to disassemble.
3. Bit operation,-1 right shift, left 1, it is still -1;-1 left shift, right 0, it is no longer 1.
4. Each application of the heap memory, preferably initialized, the inside is garbage data, and not empty.
5. In project development, often an engine exposes a pure virtual class, and its interface is the * * pointer variable of this class.
6. Program logic, heavy in semantics. You cannot reduce the design of a function for the simplistic code.
7. *& represents a reference to a pointer.
8. A static method of a class cannot invoke its non-static method, nor can it invoke a non-static member variable.
9. When multiple files are programmed, the header files cannot be included with each other.
10. Try not to use the using namespace STD in the header file;
The static member definition is placed inside the CPP file instead of in the header file.
12. Pure virtual class try not to extend more than two layers.
Include references as much as possible in CPP files.
14. Subclasses inherit the parent class and cannot initialize the members of the parent class that are not initialized in the constructor in the constructor, that is, the members that can be initialized in the subclass constructor, only their own and parent constructors.
15. In project development, for some parameters that depend on the local environment, write a special configuration file, such as a server address.
16. The header file is only declared, not defined. In the header file, the global variable declaration must be modified with extern, the static member variable declaration placed in the header file, the definition placed in the CPP file, if the normal static variable, preferably declared and defined in the CPP, because in the CPP is only visible to this file, The header file will be copied by all CPP that references the header file in exactly the same variable.
Under Linux, when file operation, file path to take absolute path (relative path is often a bug), the file pointer to its return value to judge, to prevent null pointers.
It is good to use assert in debug state, but remember to add a # define NDEBUG,ASSERT statement to # include <cassert> before the release version will be affected by Ndebug. Here is a word of mouth, errors and exceptions are different, exceptions are unavoidable, in the release version of the indispensable, so assert cannot be used to handle exceptions.
19. Object-Oriented Programming: maintainable, reusable, scalable, and flexible.
C + + Programming optimization experience (continuous update)