Compare integer type sizes and check whether a value range fits.
The smallest type that holds the value range is often much narrower than the default. Dropping from sixty-four to sixteen bits cuts memory fourfold with no loss of information. Narrower types also improve cache utilisation, so the speed gain frequently exceeds the memory saving on large arrays.
Integer Memory
Required capacity = maximum value × 2 + 1 when signed; choose the smallest type that holds it
Required capacity = maximum value × 2 + 1 when signed; choose the smallest type that holds it The smallest type that holds the value range is often much narrower than the default. Dropping from sixty-four to sixteen bits cuts memory fourfold with no loss of information.
Narrower types also improve cache utilisation, so the speed gain frequently exceeds the memory saving on large arrays.
This calculator takes 4 inputs: Number of values to store, Largest value stored, Signed values required, Bytes currently used per value. The pre-filled defaults are a realistic starting point — replace them with figures from your own environment for a result you can act on.