In C, I can allocate a register for a variable, for example:
register int i = 0;
I am aware that Java is an interpreted language, and is many many abstractions away from the CPU.
Is there any mechanism available to even request (and if the architecture doesn't allow it, so what) that my variable remains in a register instead of moving to cache or main memory?
I don't suppose there is any way, but I have been pleasantly surprised before.
Thank you,
register
in C does not put a variable to register. It simply gives the compiler the hint, that it would probably be good to put it into a register.
In Java there is no equivalent.
If it's used enough in a short space that making it a register int would be worthwhile, then the hotspot compiler should be able to figure that out itself.
In fact, the hotspot compiler should be able to do a better job than the C/C++ compiler, because it has more information to work with. C/C++ compilers have to guess; HotSpot can measure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With