On 32-bit CPUs, is an 'integer' type more efficient than a 'short' type?

前端 未结 8 1608
离开以前
离开以前 2020-11-29 09:30

On a 32-bit CPU, an integer is 4 bytes and a short integer is 2 bytes. If I am writing a C/C++ application that uses many numeric values that will always fit within the pro

8条回答
  •  星月不相逢
    2020-11-29 10:25

    If you're using "many" integer values, the bottleneck in your processing is liable to be bandwidth to memory. 16 bit integers pack more tightly into the data cache, and would therefore be a performance win.

    If you are number crunching on a very large amount of data, you should read What Every Programmer Should Know About Memory by Ulrich Drepper. Concentrate on chapter 6, about maximizing the efficiency of the data cache.

提交回复
热议问题