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?
uint_fast32_t
(the fastest unsigned int with at least 32 bits), instead of less clear types likelong
. Let the compiler do the difficult work of figuring out the very best representation.