本文整理汇总了C++中Memory::addStats方法的典型用法代码示例。如果您正苦于以下问题:C++ Memory::addStats方法的具体用法?C++ Memory::addStats怎么用?C++ Memory::addStats使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memory
的用法示例。
在下文中一共展示了Memory::addStats方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mallinfo
int
main (int /*argc*/, char** /*argv*/) {
RcInitFile& rc = RcInitFile::getDefaultInstance();
LogFile& dbglogfile = LogFile::getDefaultInstance();
dbglogfile.setVerbosity();
int diff = 0;
// Parse the test config file
if (rc.parseFile("gnashrc")) {
runtest.pass ("rc.parseFile()");
} else {
runtest.fail ("rc.parseFile()");
}
// If we don't have support for mallinfo(), this code is useless
#if HAVE_MALLINFO
Memory mem;
mem.startStats();
mem.addStats(__LINE__); // take a sample
mem.addStats(__LINE__); // take a sample
diff = mem.diffStats();
if (mem.diffStats() == 0) {
runtest.pass("No allocations yet");
} else {
runtest.fail("No allocations yet");
}
Memory m1;
mem.addStats(__LINE__); // take a sample
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");
//.........这里部分代码省略.........