Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 11 and Version 12 of code/PerformanceTips


Ignore:
Timestamp:
Apr 12, 2017, 10:18:11 PM (8 years ago)
Author:
landauf
Comment:

fixed links

Legend:

Unmodified
Added
Removed
Modified
  • code/PerformanceTips

    v11 v12  
    11= C++ Performance Tweaking Tips =
    2 [[TracNav(TracNav/TOC_Development)]]
    32
    43== General Idea ==
     
    6867
    6968=== const functions ===
    70 Now you may think of a situation, where OtherClass has a MyClass as a membervalue:
     69Now you may think of a situation, where !OtherClass has a !MyClass as a membervalue:
    7170{{{
    7271class OtherClass
     
    8584Vector3 position = instance.getObject().getPosition();
    8685}}}
    87 But this doesn't work. Why? Because OtherClass returns a '''const''' reference to MyClass. This means, you can't change anything in MyClass. But getPosition() doesn't change anything? You're absolutely right, but the compiler doesn't know about that. You have to tell him by adding the const keyword to the function head as well:
     86But this doesn't work. Why? Because !OtherClass returns a '''const''' reference to !MyClass. This means, you can't change anything in !MyClass. But getPosition() doesn't change anything? You're absolutely right, but the compiler doesn't know about that. You have to tell him by adding the const keyword to the function head as well:
    8887{{{
    8988#!html
     
    106105 * Add '''const''' to all functions that don't change the class.
    107106
    108 And remember: '''const ObjectName&''' might look scary, but it's your friend. ;)
     107And remember: '''const !ObjectName&''' might look scary, but it's your friend. ;)
    109108
    110109== Memory Allocation and Deletion: new, delete ==
     
    156155}
    157156}}}
    158 Of course SomeClass must now delete the object reference if it isn't needed anymore.
     157Of course !SomeClass must now delete the object reference if it isn't needed anymore.
    159158 
    160159== Redundant code ==