dT{GetFrameTime()} question

I have a question about creating this variable. I’m curious the reason behind creating it as a constant in the loop? Does this not recreate this variable from scratch every single time through the loop? If so, what cleans up the old copy? Why is this a better solution than creating the variable outside the loop (as just a float, not a const float because the value needs to be able to change) and then having it grab the GetFrameTime value each iteration of the loop? Just looking to understand the thought process…

2 Likes

The reason we make it a const float is because we want to prevent other code from accidentally modifying the value stored in dT somewhere else. With the variable being const we would get a compiler error if our code was unintentially attempting to modify the value stored within dT.

This also means that we need to set the initial value of dT at the time of declaration, so if we set it outside the loop it won’t ever change.

When inside of the loop, think of the process like doing arts and crafts at your kitchen table. Once you’re done building something, you then immediately clean the table before going to the next craft to be made using the same process.

To bring the analogy to your code, both the compiler and the Operating System executing the code will manage the cleaning and recreation of declared variables in memory as they go in and out of scope or when a loop starts up again.

3 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms