Variables in functions ... What is best?

guix:
My personal preference: I use global variables with no specific names, so I can reuse them whenever it's possible :slight_smile:

Once you encounter some excruciating errors, you'll think twice about this.

@Dyslexicbloke

Local var memory/registers can be re-used by the compilers optimisations, so two variables that don't have an overlapping usage can sometimes be in the same address ( compilers decision, cannot be forced ).

If you are copying data into the variable, a local initialisation can be more efficient than a global assignment.

Memory pools are another option.

Globally allocate a block/pool, then using placement new operator ( search on google, c++ FAQ ) create your local object in pool, and explicitly call the destructor when finished. This allows initialisations without allocations, plus no de-allocation ( only 1 if pool isn't persistent throughout the applications lifetime ).