Performance advantages of powers-of-2 sized data?

后端 未结 5 868
陌清茗
陌清茗 2020-12-23 22:34

If I have a game which has a 3D world, and the world is quite big, so needs to be split into chunks, is there a major, if any, performance advantage of having 128 byte chunk

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-23 23:12

    Powers of two are used a lot in software because it's the number-base that computers use.

    For example, OS's will allocate memory in block sizes of powers of two, the cache sizes in the processor are powers of two, address sizes are powers of two and so on.

    Operations using powers of two values can also be optimised - a multiply or divide becomes a simple bit shift.

    Basically ensuring everything uses powers of two might improve the performance of your software, but normally a compiler and/or OS will ensure that your data is utilised in an effective way when you use arbitrary sizes.

提交回复
热议问题