C++中, 结构体外定义位域有什么好处?
ringa_lee
ringa_lee 2017-04-17 15:17:17
0
1
434

比如

uint8 bPendingNetUpdate:1;

取代bool型变量。

实际上这个东西真地只占一个bit吗?

ringa_lee
ringa_lee

ringa_lee

reply all(1)
小葫芦

occupies one bit, but the structure will have padding for memory alignment, so just one bit field does not actually save memory. .
Being more compact will save memory. For example, connecting several flag variables of this type will definitely save memory than bool

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template