Will a long-integer work on a 32 bit system?

user3412636 picture user3412636 · Mar 12, 2014 · Viewed 9.4k times · Source

If I understand it right an int-variable is saving in 32 bit, restricting it to -2 billion to 2 billion something. However if I use a long-variable it will save in 64 bit allowing a lot more numbers to be stored. I'm sitting on a 64 bit system, but will my code run well on a 32 bit system if I store data in 64 bit?

Thank you!

Answer

dcastro picture dcastro · Mar 12, 2014

Don't you worry about that. The long value will be stored in 2 memory addresses. Int64/long will always be 64bit, and Int32/int will always be 32bit.

There are a few implications (concerning memory space and performance), but the most noticeable may be that write/read operations won't be atomic on 32bit systems, but you shouldn't expect them to be atomic anyway, since the c# specification makes no such guarantee.

Either way, the point is: this is not something you should ever worry about - the CLR abstracts these things away. Use whichever type suits you best.