Java variables

Status
Not open for further replies.

wb

Ars Legatus Legionis
25,208
Subscriptor
Well, one advantage is you don't need to do tricks with sizeof and/or multiple #defines if you're trying to write code that works correctly on several platforms, and happens to do a lot of bit-level stuff (e.g. a device driver).

A disadvantage, I guess, is that we are now stuck with those sizes for variables. Just as integers in C and C++ have slowly crept up from 8 bit values to 16, 32, and now on some systems 64 bits, Moore's law and constantly evolving software might dictate in the future that microprocessors do a lot of 128 bit or higher integer math, and in java we'll be forced to either come up with a new type, or use something like BigInt and map the implementations to the processor more effectively.

As a side note, anyone know what happens if I use BigInt to do, say, 32 bit math? Does it slow down calculations to depend on BigInt, or does it map to the underlying architecture efficiently?

 

earl

Well-known member
3,066
JackCrack: IMO the biggest disadvantage to gauranteeing the bit size of variables is something WB only touched on. If the native word size on a machine is X, it is normally very inefficient to do math operations on any other size variable. However, at the very least, the processor will have to implement some fancy register tricks or you waste a lot of space.

At least, on say x86, it is my understanding that 16b arithmetic is relatively inefficient compared to 32b (I could be wrong.)

And as WB also mentioned, on say an Alpha which currently has a 64b word, if you don't efficiently map BigInt to native size words then you are stuck using very inefficent variables to do math that fully utilizes the machine's capabilities.

-earl-
 
Status
Not open for further replies.