I'm learning to program microcontrollers and am trying to develop good habits:
Suppose I have a set of values which can be calculated based on what is already in memory. As a general rule, is it always better to calculate the data once, and save it in memory, or is it always better to calculate it each time it's needed?
My guess would be that since reading and writing to memory is slower than processor operations, it would always be better to calculate something each time it's needed rather than storing the value in memory, provided the calculation is somewhat trivial.
Am I correct in my thinking?