From a memory-only perspective, using short
instead of int
will be better. The simple reason is that a short
variable needs only half the size of an int
variable in memory. The CLR does not expand short
to int
in memory.
Nevertheless this reduced memory consumption might and probably will decrease runtime performance of your application significantly. All modern CPUs do perform much better with 32bit numbers than with 16bit numbers. Additionally in many cases the CLR will have to convert between short
and int
when e.g. calling methods that take int
arguments. There are many other performance considerations you have to take before going this way.
I would only change this at very dedicated locations and modules of your application and only if you really encounter measurable memory shortages.
In some cases you can of course switch from int
to short
easily without hurting performance. One example is a giant array of int
s all of which do also fit to short
s.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…