本文整理汇总了C++中Counter::currentTotal方法的典型用法代码示例。如果您正苦于以下问题:C++ Counter::currentTotal方法的具体用法?C++ Counter::currentTotal怎么用?C++ Counter::currentTotal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Counter
的用法示例。
在下文中一共展示了Counter::currentTotal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fill
static void fill(Counter &counter, const typename Counter::Container &container, bool fragmented)
{
qint64 allocated = 0;
QHash<void *, int> allocations;
for (int i = 0; i < 100; ++i) {
for (int j = 0; j < 100; ++j) {
int amount = fragmented ? j : i;
allocated += amount;
counter.request(amount);
void *alloc = malloc(amount);
allocations.insertMulti(alloc, amount);
counter.obtain(reinterpret_cast<quintptr>(alloc));
QCOMPARE(counter.currentTotal(), allocated);
}
}
QCOMPARE(allocated, 99 * 50 * 100);
QCOMPARE(counter.currentTotal(), allocated);
QCOMPARE(sum(container), allocated);
for (auto it = allocations.begin(), end = allocations.end(); it != end; ++it) {
free(it.key());
counter.release(reinterpret_cast<quintptr>(it.key()));
allocated -= it.value();
QCOMPARE(counter.currentTotal(), allocated);
}
allocations.clear();
QCOMPARE(allocated, 0);
QCOMPARE(counter.currentTotal(), 0);
QCOMPARE(sum(container), 0);
}