Is there a difference between asking 1byte boolean variable and 4byte int type variable when asking if??
To write it down briefly, it is as follows
boolean infiniteMode;
int gameScore;
[1]
if(infiniteMode)
{
//Infinite Mode Logic
}
else
{
//normal mode logic
}
[2]
if(gameScore >= 55)
{
//Infinite Mode Logic
}
else
{
//normal mode logic
}
[1][2] Logic with the same meaning.
It's already [2], but I need to improve the performance...
[2]->[1] I'm thinking about it.
I'd appreciate it if you could tell me if this is a lie or not.
java if문
Boolean is also stored as int on jvm (save as 4 bytes in stack frame)
So boolean is zero or one in int.
There is no mnemonic (command) for boolean comparison even in byte code.
Of course... the method chicature is divided into I and Z, but it looks like the same byte code will come out within the method (oracle JVM only (up to at least 8 versions), but as far as I know, IBM JVM is the same.)
The JVM implementation is entirely vendor responsibility, so reading the specifications is a surefire way.
In summary, in JVM, boolean is treated as 4 bytes. So the comparison in if is the same as boolean or int.
boolean isFlag = true;
if(isFlag)
...
...
int isFlag = 1;
if(isFlag > 0)
The two above are the same. (Of course, method signatures are different.)
But if the question is greater than or equal to 54...is added as a regional variable because it has been entered. In other words, a byte code longer than the boolean processing code must be processed.
In this case, the boolean generates a shorter byte code. You only need to use ifne, which is a command that is not zero.
581 PHP ssh2_scp_send fails to send files as intended
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
611 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.