加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 为什么我应该使用1位位域而不是布尔?

发布时间:2020-12-16 09:54:56 所属栏目:百科 来源:网络整理
导读:UCLASS(abstract,config=Game,BlueprintType,hidecategories=("Pawn|Character|InternalEvents"))class ENGINE_API ACharacter : public APawn{ GENERATED_UCLASS_BODY() ... UPROPERTY(Transient) uint32 bClientWasFalling:1; /** If server disagrees wit
UCLASS(abstract,config=Game,BlueprintType,hidecategories=("Pawn|Character|InternalEvents"))
class ENGINE_API ACharacter : public APawn
{
    GENERATED_UCLASS_BODY() 
...
    UPROPERTY(Transient)
    uint32 bClientWasFalling:1; 

    /** If server disagrees with root motion track position,client has to resimulate root motion from last AckedMove. */
    UPROPERTY(Transient)
    uint32 bClientResimulateRootMotion:1;

    /** Disable simulated gravity (set when character encroaches geometry on client,to keep him from falling through floors) */
    UPROPERTY()
    uint32 bSimGravityDisabled:1;

    /** 
     * Jump key Held Time.
     * This is the time that the player has held the jump key,in seconds.
     */
    UPROPERTY(Transient,BlueprintReadOnly,VisibleInstanceOnly,Category=Character)
    float JumpKeyHoldTime;

上面的代码来自UE4.他们似乎使用uint32一位bitfield而不是bools.他们为什么要这样做?

解决方法

一个独立的bool至少有一个字节长.处理器无法处理较小的单元.但是,我们都知道一个字节可以容纳8位/ bool,所以如果你有一个包含多个bool的数据结构,那么每个都不需要一个字节.他们可以共享一个字节.如果你有很多这样的结构,它可能会节省一些内存.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读