本文整理汇总了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
}