Home arrow C++ arrow Page 6 - Temporary Variables: Procrastination is the Thief of Time
C++

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.

Author Info:
By: J. Nakamura
Rating: 5 stars5 stars5 stars5 stars5 stars / 6
September 19, 2005
TABLE OF CONTENTS:
  1. · Temporary Variables: Procrastination is the Thief of Time
  2. · Temporary Object Terminology
  3. · More than just a call
  4. · To return or not to return an object
  5. · Visualizing the unseen object
  6. · Back to the closest Enemy

print this article
SEARCH DEVARTICLES

Temporary Variables: Procrastination is the Thief of Time - Back to the closest Enemy
(Page 6 of 6 )

Our example function has to find the closest enemy to the player and doesn’t contain any static data, but here there is no need for static or temporary data at all. The enemies are passed into the function via a list that already exists outside the function’s scope, and we might as well work directly with that list.

The problem that immediately pops up with this function is the fact that the whole enemy list is passed by value and we have already considered the cost of creating copies of linked lists!

This is still pretty basic stuff. One thing you might not expect is that a parameter passed as const reference can perform as bad as a parameter passed by value! We’ll be looking at that in the next article.


References

 [Meyers] – Scott Meyers

“Effective C++” – ISBN 0201924889

[Sutter] – Herb Sutter

“Exceptional C++” -  ISBN 0201615622

[Niebler] – Eric Niebler

“Conditional Love: FOREACH Redux”

http://www.artima.com/cppsource/foreach.html

[Kernighan] – Brian Kernighan (interview)

http://www-2.cs.cmu.edu/~mihaib/kernighan-interview/


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
C++ ARTICLES

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- More Tricks to Gain Speed in Programming Con...
- Easy and Efficient Programming for Contests
- Preparing For Programming Contests
- Programming Contests: Why Bother?
- Polymorphism in C++
- Overview of Virtual Functions
- Inheritance in C++
- Extending the Basic Streams in C++
- Using Stringstreams in C++
- Custom Stream Manipulation in C++
- General Stream Manipulation in C++
- Serialize Your Class into Streams in C++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials