Bit Aligning for Space and Performance Boosts

后端 未结 5 2103
闹比i
闹比i 2021-02-14 23:03

In the book Game Coding Complete, 3rd Edition, the author mentions a technique to both reduce data structure size and increase access performance. In essence it relies

5条回答
  •  眼角桃花
    2021-02-14 23:29

    Modern compilers align members on different byte boundaries depending on the size of the member. See the bottom of this.

    Normally you really shouldn't care about structure padding but if you have an object that is going to have 1000000 instances or something the rule of the thumb is simply to order your members from biggest to smallest. I wouldn't recommend messing with the padding with #pragma directives.

提交回复
热议问题