void test1() { MemPool mp; void* p = mp.alloc(100); mp.printInfo(); p = mp.alloc(100); mp.printInfo(); mp.free(p); mp.printInfo(); void* p1 = mp.alloc(100); mp.printInfo(); void* p2 = mp.alloc(100); mp.printInfo(); void* p3 = mp.alloc(100); mp.printInfo(); void* p4 = mp.alloc(100); mp.printInfo(); void* p5 = mp.alloc(256); mp.printInfo(); void* p6 = mp.alloc(257); mp.printInfo(); mp.free(p1); mp.printInfo(); mp.free(p2); mp.printInfo(); mp.free(p3); mp.printInfo(); mp.free(p4); mp.printInfo(); }
AbstractGestureEvent* event(const Event & e){ static const double minimumDPos = 25; if( e.type()==Event::MouseDown && state==NonActivated ){ MouseEvent& me = (MouseEvent&)e; if( me.button==MouseEvent::ButtonLeft ){ state = Press; pointer = me.mouseID; spos = me.pos(); pos = spos; } } if( e.type()==Event::MouseMove && state==Press ){ MouseEvent& me = (MouseEvent&)e; if( me.mouseID==pointer && (me.pos() - spos).manhattanLength() > minimumDPos ){ state = Move; pos = me.pos(); return pool.alloc(this, spos, pos, Point(), AbstractGestureEvent::GestureStarted); } } if( e.type()==Event::MouseMove && state==Move ){ MouseEvent& me = (MouseEvent&)e; if( me.mouseID==pointer ){ Point d = (me.pos()-pos); pos = me.pos(); return pool.alloc(this, spos, pos, d, AbstractGestureEvent::GestureUpdated); } } if( e.type()==Event::MouseUp && (state==Move || state==Press) ){ MouseEvent& me = (MouseEvent&)e; if( me.mouseID==pointer ){ state = NonActivated; Point d = (me.pos()-pos); return pool.alloc( this, spos, pos, d, AbstractGestureEvent::GestureFinished ); } } return 0; }
PPMonoidElemRawPtr PPMonoidOvImpl::myNew(const std::vector<long>& expv) const { CoCoA_ASSERT(myCheckExponents(expv)); PPMonoidElemRawPtr rawpp(myMemMgr.alloc()); myAssign(rawpp, expv); // cannot throw return rawpp; }
RingElemRawPtr RingFpLogImpl::myNew(ConstRawPtr rawy) const { value_t* ans = static_cast<value_t*>(myMemMgr.alloc()); *ans = import(rawy); return RingElemRawPtr(ans); }
RingElemRawPtr RingFpLogImpl::myNew(const BigInt& N) const { value_t* ans = static_cast<value_t*>(myMemMgr.alloc()); *ans = myImpl.myReduce(N); return RingElemRawPtr(ans); }
RingElemRawPtr RingFpLogImpl::myNew() const { value_t* ans = static_cast<value_t*>(myMemMgr.alloc()); *ans = 0; return RingElemRawPtr(ans); }
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); }
PPMonoidElemRawPtr PPMonoidOvImpl::myNew(PPMonoidElemConstRawPtr rawcopypp) const { PPMonoidElemRawPtr rawpp(myMemMgr.alloc()); myAssign(rawpp, rawcopypp); // cannot throw return rawpp; }
PPMonoidElemRawPtr PPMonoidOvImpl::myNew() const { PPMonoidElemRawPtr rawpp(myMemMgr.alloc()); myAssignOne(rawpp); // cannot throw return rawpp; }