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


C++ MemPool::begin方法代码示例

本文整理汇总了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);
    }
开发者ID:FUKUZAWA-Tadashi,项目名称:Hayat,代码行数:99,代码来源:Test_hyGC.cpp


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