本文整理汇总了C++中MemPool::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ MemPool::begin方法的具体用法?C++ MemPool::begin怎么用?C++ MemPool::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemPool
的用法示例。
在下文中一共展示了MemPool::begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_markSweep
void test_markSweep(void)
{
MemPool* orgMemPool = gMemPool;
void* tmp = HMD_ALLOC(2048);
MemPool::initGMemPool(tmp, 2048);
GC::initialize();
MemPool* pool = gMemPool;
Object* o1 = Object::create(HC_StringBuffer, 20);
MemCell* c2 = pool->alloc(40);
Object* o3 = Object::create(HC_StringBuffer, 60);
MemCell* c4 = pool->alloc(80);
Object* o5 = Object::create(HC_StringBuffer, 100);
Object* o6 = Object::create(HC_StringBuffer, 120);
Object* o7 = Object::create(HC_StringBuffer, 80);
MemCell* c8 = pool->alloc(100);
Object* o9 = Object::create(HC_StringBuffer, 60);
Object* o10 = Object::create(HC_StringBuffer, 40);
// ObjectはGCObjectで、MemCellはGCObjectではない
CPPUNIT_ASSERT(((MemCell*)o1)->isGCObject());
CPPUNIT_ASSERT(((MemCell*)o3)->isGCObject());
CPPUNIT_ASSERT(((MemCell*)o5)->isGCObject());
CPPUNIT_ASSERT(((MemCell*)o6)->isGCObject());
CPPUNIT_ASSERT(((MemCell*)o7)->isGCObject());
CPPUNIT_ASSERT(((MemCell*)o9)->isGCObject());
CPPUNIT_ASSERT(((MemCell*)o10)->isGCObject());
CPPUNIT_ASSERT(! c2->isGCObject());
CPPUNIT_ASSERT(! c4->isGCObject());
CPPUNIT_ASSERT(! c8->isGCObject());
// Object生成当初はマークされている
CPPUNIT_ASSERT(o1->isMarked());
CPPUNIT_ASSERT(o3->isMarked());
CPPUNIT_ASSERT(o5->isMarked());
CPPUNIT_ASSERT(o6->isMarked());
CPPUNIT_ASSERT(o7->isMarked());
CPPUNIT_ASSERT(o9->isMarked());
CPPUNIT_ASSERT(o10->isMarked());
GC::unmark();
CPPUNIT_ASSERT(! o1->isMarked());
CPPUNIT_ASSERT(! o3->isMarked());
CPPUNIT_ASSERT(! o5->isMarked());
CPPUNIT_ASSERT(! o6->isMarked());
CPPUNIT_ASSERT(! o7->isMarked());
CPPUNIT_ASSERT(! o9->isMarked());
CPPUNIT_ASSERT(! o10->isMarked());
o3->m_mark();
o5->m_mark();
o6->m_mark();
o9->m_mark();
CPPUNIT_ASSERT(o3->isMarked());
CPPUNIT_ASSERT(o5->isMarked());
CPPUNIT_ASSERT(o6->isMarked());
CPPUNIT_ASSERT(o9->isMarked());
// 回収
GC::sweep();
// freeじゃないのはMemCellとmarkしたObjectとfinalize用Context
int flag = 0;
for (CellIterator itr = pool->begin(); itr < pool->end(); itr++) {
MemCell* cell = *itr;
if (! cell->m_bFree()) {
if (cell == c2) {
CPPUNIT_ASSERT((flag & 0x01) == 0);
flag |= 0x01;
} else if (cell == c4) {
CPPUNIT_ASSERT((flag & 0x02) == 0);
flag |= 0x02;
} else if (cell == c8) {
CPPUNIT_ASSERT((flag & 0x04) == 0);
flag |= 0x04;
} else if (cell == (MemCell*)o3) {
CPPUNIT_ASSERT((flag & 0x08) == 0);
flag |= 0x08;
} else if (cell == (MemCell*)o5) {
CPPUNIT_ASSERT((flag & 0x10) == 0);
flag |= 0x10;
} else if (cell == (MemCell*)o6) {
CPPUNIT_ASSERT((flag & 0x20) == 0);
flag |= 0x20;
} else if (cell == (MemCell*)o9) {
CPPUNIT_ASSERT((flag & 0x40) == 0);
flag |= 0x40;
}
}
}
CPPUNIT_ASSERT(flag == 0x7f);
GC::finalize();
gMemPool = orgMemPool;
HMD_FREE(tmp);
}