Original Post
Yes, I know, it is the root of all evil when premature. Really, I'm not planning to apply this, I promise. I'm just curious. [/disclaimer] I've been reading about caches. Assume you have many methods with different temporary variables in them. Let's say they are all floats, and only one per method. Can you avoid cache misses by declaring a global float, which (I hope) the compiler will then assign a permanent cache address since it is used so often? Or are compilers already smart enough for this, so that they use one or two cache positions for temporary variables? In fact, perhaps declaring a global variable for such use would actually slow down your program, if the compiler felt obliged to write it to memory once in a while? In a somewhat similar vein, if you have two for loops close to each other, could you save yourself a miss by declaring one counter int and reusing it? Or perhaps the compiler will already do this for you?