I read in the book "Game Engine Architecture" by Jason Gregory that:
"It’s possible to access data items that are narrower than the width of a machine’s data bus, but it’s typically more costly than accessing items whose widths match that of the data bus. For example, when reading a 16-bit value on a 64-bit machine, a full 64 bits worth of data must still be read from memory. The desired 16-bit field then has to be masked off and possibly shifted into place within the destination register."
So, if I just use long long (64 bit integers), will my code be faster than if I use less bits integers (short, int)? If so, why still using shorts and ints if we can get larger values (when needed) and faster code with just long longs?
Best Answer
In practice, it's not going to matter most of the time.
And so, in order for this to matter, there must be:
"Materially" means that:
In short, measure. Profile your code using both techniques, and then use those measurements to determine what to do. It's the only way to be sure.
Incidentally, this is the reason many programming languages use a 32 bit signed integer as the default numeric type. It's usually the best compromise for speed, flexibility, storage space and numeric resolution.