zoukankan      html  css  js  c++  java
  • HBufC 的 zero 方法测试

    HBufC 的 zero 方法测试
    今天看到 HBufC 的Zero 方法了,帮助中说是

    Zero()

    IMPORT_C void Zero();

    Description

    Sets the length of the data to zero.

    把 Lenght 设为  0 了,那内容还存不存在,下面是试验代码

    HBufC* aTest = HBufC::NewL(12);
     CleanupStack::PushL(aTest);
     _LIT(KTest,"qijianzhou");
     TPtr ptr = aTest->Des();
     TBuf<12> aBuf(KTest);
     ptr.Append(aBuf);
     _LIT(KFormat1,"length=%d\nsize=%d\ncontent=%S");
     console->Printf(KFormat1,aTest->Length(),aTest->Size(),&ptr);
     console->Getch();
     ptr.Zero();
        console->Printf(KFormat1,aTest->Length(),aTest->Size(),&ptr);
     CleanupStack::PopAndDestroy();

    经过试验,发现 内容给清空,同时 length 为 0

    再测试一下刚创建后的 length 及 size
    _LIT(KFormat1,"length=%d\nsize=%d\ncontent=%S");
     HBufC* aTest = HBufC::NewL(12);
     
     CleanupStack::PushL(aTest);
     _LIT(KTest,"qijianzhou");
     TPtr ptr = aTest->Des();
     TBuf<12> aBuf(KTest);
     // 测试刚创建完后长度及大小
     console->Printf(KFormat1,aTest->Length(),aTest->Size(),&ptr);
     console->Getch();
     ptr.Append(aBuf);
     
     console->Printf(KFormat1,aTest->Length(),aTest->Size(),&ptr);
     console->Getch();
     ptr.Zero();
        console->Printf(KFormat1,aTest->Length(),aTest->Size(),&ptr);
     CleanupStack::PopAndDestroy();

    经测试,刚创建后的 Length 及 Size 都为 0,内容为空

    如果对于 HBufC 及 TBuf ,赋值时,内容长度大于指定的长度,则程序会出现异常



    安平2009@原创
    qi_jianzhou@126.com

  • 相关阅读:
    VRChat简易教程1-开发环境准备(SDK)
    BeatSaber节奏光剑插件开发官方教程2-简单的插件示例
    BeatSaber节奏光剑插件开发官方教程1-创建一个插件模板
    BeatSaber节奏光剑双手柄MR教程
    第四章 HTML与JavaScript
    第二章数据和判定
    蓝港在线笔试经验
    数据结构总复习(查找)
    数据结构总复习(3)
    数据结构总复习(2)
  • 原文地址:https://www.cnblogs.com/zziss/p/1648718.html
Copyright © 2011-2022 走看看