8 ms·
> Perf: if you don't care about the size, you might as well use the native size, which is supposed to be faster. You always care about the size (or should), es
by epcoa 2y ago
> Perf: if you don't care about the size, you might as well use the native size, which is supposed to be faster.
You always care about the size (or should), especially if you're writing C or C++.
Though it is often reasonable that 32767 is a sufficient limit and you're guaranteed at least that with int.
- jraph 2y agoWhat I meant is that if you don't specifically need a small int size (because for instance you are going to serialize it into a format that mandates it), and you will not deal with even moderately large ints, you will probably use int even if you could use a smaller type. I've not seen many codebases doing something else. Of course you need to think about it. In C, but also in many languages (not python though, which magically switch to bigint when needed). In Java, the wrong int type won't cause UB, but it will throw (unchecked) exceptions.