Int datatype in 64bit JVM. Is it more "ineffective" than long?

I've heard that using it short

on a 32-bit system is just more inefficient than using int

s. Is this the same for int

on a 64-bit system?

Recently Python (?) Has basically merged int

with long

and has basically one data type long

, right? If you are sure your application. will only work on 64bit, is it possible at all (maybe a good idea) to use for Java all the time?

+2


a source to share


2 answers


A Python long

is arbitrary precision, not 64 bit. Python 3 changed long

to int

so that there is now only one arbitrary precision integral type, which saves a lot of work for the programmer. Java int is 32 bit, it is long 64 bit. A 64-bit processor can usually perform better than a 32-bit processor with a 64-bit integer.



Using 32-bit integers on a 64-bit platform is not expensive, at least not on x64. It doesn't make sense to choose 32bit over 64bit int or vise-versa in Java just for performance reasons. If you used two 32-bit ints instead of one 64-bit int, it would be slower no matter what. Likewise, if you are using the 64-bit version where you could use the 32-bit version, it will be slower on some platforms. In other words, use the correct data type for the problem domain.

+2


a source


If you are sure your application. will only work on 64bit, is it possible at all (maybe a good idea) to use for Java all the time?

Bad idea, IMO

Even if there is a difference between using int

and long

in a 64-bit JVM (which is highly questionable in my opinion), it won't be significant enough for the entire application, including the libraries you depend on to use long

for everyone.



And there are some potential problems:

  • You will use more memory, at least for long[]

    compared to int[]

    .
  • You will regret if your assumption that you do not need to run on a 32-bit platform turns out to be wrong.

(The reason I think there won't be a significant performance difference, the problem is that the problem, if any, would be retrieving and storing unaligned int-32s. But if so, JVM designers are more likely to want int -32 are always aligned to 64-bit word addresses.JVMs usually do this with int-8 and int-16 on 32-bit architectures ...)

+2


a source







All Articles