当前位置: 首页>>代码示例>>C++>>正文


C++ Memory::analyze方法代码示例

本文整理汇总了C++中Memory::analyze方法的典型用法代码示例。如果您正苦于以下问题:C++ Memory::analyze方法的具体用法?C++ Memory::analyze怎么用?C++ Memory::analyze使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Memory的用法示例。


在下文中一共展示了Memory::analyze方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mallinfo


//.........这里部分代码省略.........
    diff = mem.diffStats();
//    cerr << "Memory::Memory: " << diff << endl;
    if ((diff >= 8) || (diff <= 16)) {
        runtest.pass("Memory::Memory");
    } else {
        runtest.fail("Memory::Memory");
    }
    
    if (mem.diffStamp() > 0) {
        runtest.pass("Memory::diffStamp()");
    } else {
        runtest.fail("Memory::diffStamp()");
    }

    if (mem.diffStats() > 0) {
        runtest.pass("Memory::diffStats()");
    } else {
        runtest.fail("Memory::diffStats()");
    }

    char *x = new char[120];
    mem.addStats(__LINE__);             // take a sample
    diff = mem.diffStats();
//    cerr << "Buffer allocation: " << diff << endl;
    if ((diff >= 104) && (diff <= 136)) {
        runtest.pass("Buffer allocation");
    } else {
        runtest.fail("Buffer allocation");
    }
    
    vector<string> sv;
    sv.push_back("Hello World");
    mem.addStats(__LINE__);             // take a sample
    diff = mem.diffStats();
//    cerr << "First string allocated: " << diff << endl;
    if ((diff >= 40) && (diff <= 48)) {
        runtest.pass("First string allocated");
    } else {
        runtest.fail("First string allocated");
    }

    sv.push_back("Aloha");
    delete x;
    mem.addStats(__LINE__);             // take a sample
    diff = mem.diffStats();
//    cerr << "Second string allocated: " << diff << endl;
    if ((diff >= -104) && (diff <= -96)) {
        runtest.pass("Second string allocated");
    } else {
        runtest.fail("Second string allocated");
    }

    sv.push_back("Guten Tag");
    mem.addStats(__LINE__);             // take a sample
    diff = mem.diffStats();
//    cerr << "Third string allocated: " << diff << endl;
    if ((diff >= 40) && (diff <= 48)){
        runtest.pass("Third string allocated");
    } else {
        runtest.fail("Third string allocated");
    }

    mem.startCheckpoint();
    test_leak();
    if (mem.endCheckpoint()) {
        runtest.fail("leak");
    } else {
        runtest.pass("leak");
    }    
    mem.addStats(__LINE__);             // take a sample
    if (mem.diffStats() == 32) {
        runtest.pass("test_leak");
    } else {
        runtest.fail("test_leak");
    }

    mem.startCheckpoint();
    test_noleak();
    mem.addStats(__LINE__);             // take a sample
    if (mem.endCheckpoint()) {
        runtest.pass("noleak");
    } else {
        runtest.fail("noleak");
    }
    diff = mem.diffStats();
    if ((diff >= 0) && (diff <= 8)) {
        runtest.pass("test_noleak");
    } else {
        runtest.fail("test_noleak");
    }
    
    mem.endStats();

//    mem.dump();

    mem.analyze();
#else
    runtest.untested("No support for mallinfo()");
#endif // end of HAVE_MALLINFO
}
开发者ID:BrandRegard,项目名称:gnash,代码行数:101,代码来源:memtest.cpp


注:本文中的Memory::analyze方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。