Linux programming-C ++ game program optimization-general Linux technology-Linux programming and kernel information. For details, see the following. In general, C ++ games are reusable and maintainable compared with C Programs. But is this really valuable? Can complicated C ++ be compared with traditional C Programs in terms of speed?
If you have a good compiler and a good understanding of the language, it is really possible to use C ++ to write some efficient game programs. This article describes several typical techniques you can use to accelerate your game. It assumes that you are already very certain about the benefits of using C ++, and you are quite familiar with the basic concepts of optimization.
The first basic concept that often benefits people is obviously the importance of profiling. If there is a lack of profiling, the programmer will make two kinds of errors. One is to optimize the wrong code: if the main indicator of a program is not efficiency, it is a waste of time to make it more efficient. Intuition is used to determine which code's main indicator is that efficiency is not credible and can only be measured directly. The second concept is that programmers often "optimize" to reduce the speed of code. This is a typical problem in C ++. A simple command line may generate a large number of machine code. You should always check the output of your compiler and analyze it.
1. Object Construction and Analysis
Object Construction and analysis is one of the core concepts of C ++ and a major part of the code generated by the compiler. Uncarefully designed programs often spend a lot of time calling constructors, copying objects and initializing temporary objects. Fortunately, the general feeling and a few simple rules can make the heavy object code run as little as C. It is not constructed unless necessary. The fastest code is the code that does not run at all. Why do you want to create an object that you don't even use? In the code below: