Temporary Variables: Procrastination is the Thief of Time
C++ is a powerful programming language to learn, in part because it gives you full control over memory management. This is a two-edged sword, however; it lets you improve the performance of your code, but it also lets you shoot yourself in the foot. Therefore, it is important to understand the C++ compiler. This article examines how and why the compiler creates temporary objects, among other topics.
Temporary Variables: Procrastination is the Thief of Time (Page 1 of 6 )
Performance is wasted when you know the value of everything but the price of nothing.
It is not too difficult to learn a programming language like C++ when you are already familiar with another object oriented programming language such as Java or C#. Just don’t mistake the knowledge of syntax for the knowledge of semantics, because once you’ve learned the C++ syntax your programming journey is only about to begin. After you have dealt with the books and courses that help you to teach yourself C++, you will discover a need for other books that help you to become effective and exceptional at it.
One of the reasons that the C++ programming language is so powerful is because it is a very flexible language. It extends C with numerous higher level programming concepts, but remains lean and mean enough for your application to maintain good performance.
Where other languages try to make life easier for a programmer by offering features like garbage collection (which seems to be part of every new programming language these days), C++ gives you full control over memory management and basically everything else. All these "safety" features offered by other languages suffer from one thing: performance. The reason for this is that you will need fine-grained control over the final machine code that is going to run on your target platform if you want to be able to maximize performance. This is the same gun that allows you to shoot yourself in the foot… the same gun that can make C++ so powerful.
Understanding the compiler is an important step in our semantic journey. Luckily we do not have to learn the behavior of all C++ compilers, since the C++ Standard binds them all in their functionality and behavior. In this article we are going to examine temporary objects: how and why the compiler creates them, why they can be useful, when they should be avoided and how we can help the compiler to optimize our code to make them go away.