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


C++ CAutoMemoryPool类代码示例

本文整理汇总了C++中CAutoMemoryPool的典型用法代码示例。如果您正苦于以下问题:C++ CAutoMemoryPool类的具体用法?C++ CAutoMemoryPool怎么用?C++ CAutoMemoryPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CAutoMemoryPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: str

//---------------------------------------------------------------------------
//	@function:
//		CTreeMapTest::EresUnittest_Count
//
//	@doc:
//		Count and debug output of all counts at various nodes
//
//---------------------------------------------------------------------------
GPOS_RESULT
CTreeMapTest::EresUnittest_Count()
{
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();
	
	TestMap *ptmap = PtmapLoad(pmp);	
	
	// debug print
	CWStringDynamic str(pmp);
	COstreamString oss(&str);

	ULLONG ullCount = ptmap->UllCount();
	oss << "total number of trees: " << ullCount << std::endl;
	
#ifdef GPOS_DEBUG

	for (ULONG ul = 0; ul < ulElems; ul++)
	{
		oss << "node: " << ul 
			<< " count: " << ptmap->UllCount(&rgul[ul]) 
			<< std::endl;
	}

	(void) ptmap->OsPrint(oss);

#endif // GPOS_DEBUG

	GPOS_TRACE(str.Wsz());
	GPOS_DELETE(ptmap);

	return GPOS_OK;
}
开发者ID:HanumathRao,项目名称:gporca,代码行数:41,代码来源:CTreeMapTest.cpp

示例2:

//---------------------------------------------------------------------------
//	@function:
//		CMessageTableTest::EresUnittest_Basic
//
//	@doc:
//		Create message table and insert all standard messages;
//
//---------------------------------------------------------------------------
GPOS_RESULT
CMessageTableTest::EresUnittest_Basic()
{
	// create memory pool
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();

	CMessageTable *pmt = GPOS_NEW(pmp)
		CMessageTable(pmp, GPOS_MSGTAB_SIZE, ElocEnUS_Utf8);
	
	// insert all system messages
	for (ULONG ul = 0; ul < CException::ExmiSentinel; ul++)
	{
		CMessage *pmsg = CMessage::Pmsg(ul);
		if (CException::m_excInvalid != pmsg->m_exc)
		{
			pmt->AddMessage(pmsg);

#ifdef GPOS_DEBUG
			CMessage *pmsgLookedup = pmt->PmsgLookup(pmsg->m_exc);
			GPOS_ASSERT(pmsg == pmsgLookedup && "Lookup failed");
#endif // GPOS_DEBUG
		}
	}
		
	GPOS_DELETE(pmt);
	
	return GPOS_OK;
}
开发者ID:MoZhonghua,项目名称:gporca,代码行数:37,代码来源:CMessageTableTest.cpp

示例3: atfDump

//---------------------------------------------------------------------------
//	@function:
//		CMemoryPoolBasicTest::EresLeakByException
//
//	@doc:
//		Basic test for ignored leaks under exception
//
//---------------------------------------------------------------------------
GPOS_RESULT
CMemoryPoolBasicTest::EresLeakByException
	(
	CMemoryPoolManager::EAllocType eat
	)
{
	CAutoTraceFlag atfDump(EtracePrintMemoryLeakDump, true);
	CAutoTraceFlag atfStackTrace(EtracePrintMemoryLeakStackTrace, true);
	CAutoTimer at("LeakByException test", true /*fPrint*/);

	// scope for pool
	{
		// create memory pool
		CAutoMemoryPool amp
			(
			CAutoMemoryPool::ElcExc,
			eat,
			false /*fThreadSafe*/,
			4 * 1024 * 1024 /*ullMaxSize*/
			);
		IMemoryPool *pmp = amp.Pmp();

		for (ULONG i = 0; i < 10; i++)
		{
			// use overloaded New operator
			ULONG *rgul = GPOS_NEW_ARRAY(pmp, ULONG, 3);
			rgul[2] = 1;
		}

		GPOS_ASSERT(!"Trigger leak with exception");
	}

	return GPOS_FAILED;
}
开发者ID:RalphSu,项目名称:gpos,代码行数:42,代码来源:CMemoryPoolBasicTest.cpp

示例4: CBitSet

//---------------------------------------------------------------------------
//	@function:
//		CBitSetTest::EresUnittest_Performance
//
//	@doc:
//		Simple perf test -- simulates xform candidate sets
//
//---------------------------------------------------------------------------
GPOS_RESULT
CBitSetTest::EresUnittest_Performance()
{
	// create memory pool
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();
	
	ULONG cSizeBits = 512;
	CBitSet *pbsBase = GPOS_NEW(pmp) CBitSet(pmp, cSizeBits);
	for (ULONG i = 0; i < cSizeBits; i++)
		{
			(void) pbsBase->FExchangeSet(i);
		}

	CBitSet *pbsTest = GPOS_NEW(pmp) CBitSet(pmp, cSizeBits);
	for (ULONG j = 0; j < 100000; j++)
	{
		ULONG cRandomBits = 16;
		for (ULONG i = 0; i < cRandomBits; i += ((cSizeBits - 1) / cRandomBits))
		{
			(void) pbsTest->FExchangeSet(i);
		}
			
		pbsTest->Intersection(pbsBase);		
	}	
	
	pbsTest->Release();
	pbsBase->Release();
	
	return GPOS_OK;
}	
开发者ID:RalphSu,项目名称:gpos,代码行数:39,代码来源:CBitSetTest.cpp

示例5: CMDProviderMemory

//---------------------------------------------------------------------------
//	@function:
//		CMDProviderTest::EresUnittest_Basic
//
//	@doc:
//		Test fetching existing metadata objects from a file-based provider
//
//---------------------------------------------------------------------------
GPOS_RESULT
CMDProviderTest::EresUnittest_Basic()
{
	// create memory pool
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();
	
	// test lookup with a file-based provider
	CMDProviderMemory *pmdpFile = GPOS_NEW(pmp) CMDProviderMemory(pmp, szFileName);
	pmdpFile->AddRef();
	
	TestMDLookup(pmp, pmdpFile);
	
	pmdpFile->Release();
	
	// test lookup with a memory-based provider
	CHAR *szDXL = CDXLUtils::SzRead(pmp, szFileName);

	DrgPimdobj *pdrgpmdobj = CDXLUtils::PdrgpmdobjParseDXL(pmp, szDXL, NULL /*szXSDPath*/);
	
	CMDProviderMemory *pmdpMemory = GPOS_NEW(pmp) CMDProviderMemory(pmp, pdrgpmdobj);
	pmdpMemory->AddRef();
	TestMDLookup(pmp, pmdpMemory);

	GPOS_DELETE_ARRAY(szDXL);
	pdrgpmdobj->Release();
	pmdpMemory->Release();
	
	return GPOS_OK;
}
开发者ID:HanumathRao,项目名称:gporca,代码行数:38,代码来源:CMDProviderTest.cpp

示例6: eti

//---------------------------------------------------------------------------
//	@function:
//		CEnumSetTest::EresUnittest_Basics
//
//	@doc:
//		Testing ctors/dtor, accessors, iterator
//
//---------------------------------------------------------------------------
GPOS_RESULT
CEnumSetTest::EresUnittest_Basics()
{
	// create memory pool
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();

	typedef CEnumSet<eTest, eTestSentinel> CETestSet;
	typedef CEnumSetIter<eTest, eTestSentinel> CETestIter;

	CETestSet *pes = GPOS_NEW(pmp) CETestSet(pmp);
	
	(void) pes->FExchangeSet(eTestOne);
	(void) pes->FExchangeSet(eTestTwo);
	
	GPOS_ASSERT(pes->FExchangeClear(eTestTwo));
	GPOS_ASSERT(!pes->FExchangeSet(eTestTwo));

	CETestIter eti(*pes);
	while(eti.FAdvance())
	{
		GPOS_ASSERT((BOOL)eti);
		GPOS_ASSERT(eTestSentinel > eti.TBit());
		GPOS_ASSERT(pes->FBit(eti.TBit()));
	}
	
	pes->Release();

	return GPOS_OK;
}
开发者ID:RalphSu,项目名称:gpos,代码行数:38,代码来源:CEnumSetTest.cpp

示例7: ConfigureTests

//---------------------------------------------------------------------------
//	@function:
//		ConfigureTests
//
//	@doc:
//		Configurations needed before running unittests
//
//---------------------------------------------------------------------------
void ConfigureTests()
{
	// initialize DXL support
	InitDXL();

	CMDCache::Init();

	// load metadata objects into provider file
	{
		CAutoMemoryPool amp;
		IMemoryPool *pmp = amp.Pmp();
		CTestUtils::InitProviderFile(pmp);

		// detach safety
		(void) amp.PmpDetach();
	}

#ifdef GPOS_DEBUG
	// reset xforms factory to exercise xforms ctors and dtors
	CXformFactory::Pxff()->Shutdown();
	GPOS_RESULT eres = CXformFactory::EresInit();

	GPOS_ASSERT(GPOS_OK == eres);
#endif // GPOS_DEBUG
}
开发者ID:fzhedu,项目名称:gporca,代码行数:33,代码来源:main.cpp

示例8:

//---------------------------------------------------------------------------
//	@function:
//		CSyncHashtableTest::EresUnittest_AccessorDeadlock
//
//	@doc:
//		Test for self-deadlock on hashtable accessor
//
//---------------------------------------------------------------------------
GPOS_RESULT
CSyncHashtableTest::EresUnittest_AccessorDeadlock()
{
	// create memory pool
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();

	// scope for hashtable
	{
		CSyncHashtable<SElem, ULONG, CSpinlockDummy> sht;
		sht.Init
			(
			pmp,
			GPOS_SHT_SMALL_BUCKETS,
			GPOS_OFFSET(SElem, m_link),
			GPOS_OFFSET(SElem, m_ulKey),
			&(SElem::m_ulInvalid),
			SElem::UlHash,
			SElem::FEqualKeys
			);

		SElem elem;
		elem.m_ulKey = 1;
		ULONG ulKey = elem.m_ulKey;

		CSyncHashtableAccessByKey<SElem, ULONG, CSpinlockDummy> shtacc0(sht, ulKey);

		// this must assert since we try to self-deadlock on a spinlock
		CSyncHashtableAccessByKey<SElem, ULONG, CSpinlockDummy> shtacc1(sht, ulKey);
	}

	return GPOS_FAILED;
}
开发者ID:RalphSu,项目名称:gpos,代码行数:41,代码来源:CSyncHashtableTest.cpp

示例9:

//---------------------------------------------------------------------------
//	@function:
//		CListTest::EresUnittest_Cursor
//
//	@doc:
//		Various cursor-based inserts
//
//---------------------------------------------------------------------------
GPOS_RESULT
CListTest::EresUnittest_Cursor()
{
	// create memory pool
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();

	CList<SElem> list;
	list.Init(GPOS_OFFSET(SElem, m_linkFwd));

	ULONG cSize = 5;
	SElem *rgelem = GPOS_NEW_ARRAY(pmp, SElem, cSize);

	list.Append(&rgelem[0]);

	list.Prepend(&rgelem[1], list.PtFirst());
	list.Append(&rgelem[2], list.PtLast());

	GPOS_ASSERT(&rgelem[1] == list.PtFirst());
	GPOS_ASSERT(&rgelem[2] == list.PtLast());

	list.Prepend(&rgelem[3], list.PtLast());
	list.Append(&rgelem[4], list.PtFirst());

	GPOS_ASSERT(&rgelem[1] == list.PtFirst());
	GPOS_ASSERT(&rgelem[2] == list.PtLast());

	GPOS_DELETE_ARRAY(rgelem);
	return GPOS_OK;
}
开发者ID:MoZhonghua,项目名称:gporca,代码行数:38,代码来源:CListTest.cpp

示例10:

// basic int4 point tests;
GPOS_RESULT
CPointTest::EresUnittest_CPointInt4()
{
	// create memory pool
	CAutoMemoryPool amp;
	IMemoryPool *mp = amp.Pmp();

	// generate integer points
	CPoint *point1 = CTestUtils::PpointInt4(mp, 1);
	CPoint *point2 = CTestUtils::PpointInt4(mp, 2);

	GPOS_RTL_ASSERT_MSG(point1->Equals(point1), "1 == 1");
	GPOS_RTL_ASSERT_MSG(point1->IsLessThan(point2), "1 < 2");
	GPOS_RTL_ASSERT_MSG(point2->IsGreaterThan(point1), "2 > 1");
	GPOS_RTL_ASSERT_MSG(point1->IsLessThanOrEqual(point2), "1 <= 2");
	GPOS_RTL_ASSERT_MSG(point2->IsGreaterThanOrEqual(point2), "2 >= 2");

	CDouble dDistance = point2->Distance(point1);

	// should be 1.0
	GPOS_RTL_ASSERT_MSG(0.99 < dDistance
						&& dDistance < 1.01, "incorrect distance calculation");

	point1->Release();
	point2->Release();

	return GPOS_OK;
}
开发者ID:b-xiang,项目名称:gporca,代码行数:29,代码来源:CPointTest.cpp

示例11: ss

//---------------------------------------------------------------------------
//	@function:
//		CWStringTest::EresUnittest_Initialize
//
//	@doc:
//		Test string construction
//
//---------------------------------------------------------------------------
GPOS_RESULT
CWStringTest::EresUnittest_Initialize()
{
#ifdef GPOS_DEBUG // run this test in debug mode only
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();
		
	CWStringDynamic *pstr1 = GPOS_NEW(pmp) CWStringDynamic(pmp, GPOS_WSZ_LIT("123"));
	
	CWStringConst cstr1(GPOS_WSZ_LIT("123"));
	GPOS_ASSERT(pstr1->FEquals(&cstr1));
	
	// empty string initialization
	CWStringDynamic *pstr2 = GPOS_NEW(pmp) CWStringDynamic(pmp);
	WCHAR buffer[16];
	CWStringStatic ss(buffer, GPOS_ARRAY_SIZE(buffer));
	
	CWStringConst cstr2(GPOS_WSZ_LIT(""));
	GPOS_ASSERT(pstr2->FEquals(&cstr2));
	GPOS_ASSERT(ss.FEquals(&cstr2));
	GPOS_ASSERT(0 == pstr2->UlLength());
	GPOS_ASSERT(0 == ss.UlLength());
	
	// constant string initialization
	CWStringConst *pcstr1 = GPOS_NEW(pmp) CWStringConst(GPOS_WSZ_LIT("123"));
	GPOS_ASSERT(pcstr1->FEquals(&cstr1));
	
	// cleanup
	GPOS_DELETE(pstr1);
	GPOS_DELETE(pstr2);
	GPOS_DELETE(pcstr1);
	
#endif // #ifdef GPOS_DEBUG
	return GPOS_OK;
}
开发者ID:MoZhonghua,项目名称:gporca,代码行数:43,代码来源:CWStringTest.cpp

示例12: GPOS_ASSERT

//---------------------------------------------------------------------------
//	@function:
//		CNormalizer::FPushableThruSeqPrjChild
//
//	@doc:
//		Check if a predicate can be pushed through the child of a sequence
//		project expression
//
//---------------------------------------------------------------------------
BOOL
CNormalizer::FPushableThruSeqPrjChild
	(
	CExpression *pexprSeqPrj,
	CExpression *pexprPred
	)
{
	GPOS_ASSERT(NULL != pexprSeqPrj);
	GPOS_ASSERT(NULL != pexprPred);
	GPOS_ASSERT(CLogical::EopLogicalSequenceProject == pexprSeqPrj->Pop()->Eopid());

	CDistributionSpec *pds = CLogicalSequenceProject::PopConvert(pexprSeqPrj->Pop())->Pds();
	BOOL fPushable = false;
	if (CDistributionSpec::EdtHashed == pds->Edt())
	{
		CAutoMemoryPool amp;
		IMemoryPool *pmp = amp.Pmp();
		CColRefSet *pcrsUsed = CDrvdPropScalar::Pdpscalar(pexprPred->PdpDerive())->PcrsUsed();
		CColRefSet *pcrsPartCols = CUtils::PcrsExtractColumns(pmp, CDistributionSpecHashed::PdsConvert(pds)->Pdrgpexpr());
		if (pcrsPartCols->FSubset(pcrsUsed))
		{
			// predicate is pushable if used columns are included in partition-by expression
			fPushable = true;
		}
		pcrsPartCols->Release();
	}

	return fPushable;
}
开发者ID:godouxm,项目名称:gporca,代码行数:38,代码来源:CNormalizer.cpp

示例13: atp

//---------------------------------------------------------------------------
//	@function:
//		CAutoTaskProxyTest::EresUnittest_Wait
//
//	@doc:
//		Wait for task to complete.
//
//---------------------------------------------------------------------------
GPOS_RESULT
CAutoTaskProxyTest::EresUnittest_Wait()
{
	CAutoMemoryPool amp;
	IMemoryPool *mp = amp.Pmp();

	CWorkerPoolManager *pwpm = CWorkerPoolManager::WorkerPoolManager();

	// scope for ATP
	{
		CAutoTaskProxy atp(mp, pwpm);
		CTask *rgPtsk[2];
		ULLONG rgRes[2];

		// create tasks
		rgPtsk[0] = atp.Create(CAutoTaskProxyTest::PvUnittest_Short, &rgRes[0]);
		rgPtsk[1] = atp.Create(CAutoTaskProxyTest::PvUnittest_Long, &rgRes[1]);

		// start two tasks
		atp.Schedule(rgPtsk[0]);
		atp.Schedule(rgPtsk[1]);

		// wait until tasks complete
		atp.Wait(rgPtsk[0]);
		atp.Wait(rgPtsk[1]);

		GPOS_ASSERT(rgRes[0] == *(ULLONG *)rgPtsk[0]->GetRes());
		GPOS_ASSERT(rgRes[1] == *(ULLONG *)rgPtsk[1]->GetRes());
	}


	return GPOS_OK;
}
开发者ID:b-xiang,项目名称:gporca,代码行数:41,代码来源:CAutoTaskProxyTest.cpp

示例14: mda

//---------------------------------------------------------------------------
//	@function:
//		CColumnFactoryTest::EresUnittest_Basic
//
//	@doc:
//		Basic array allocation test
//
//---------------------------------------------------------------------------
GPOS_RESULT
CColumnFactoryTest::EresUnittest_Basic()
{
	CAutoMemoryPool amp;
	IMemoryPool *pmp = amp.Pmp();

	CMDProviderMemory *pmdp = CTestUtils::m_pmdpf;
	pmdp->AddRef();
	CMDAccessor mda(pmp, CMDCache::Pcache());
	mda.RegisterProvider(CTestUtils::m_sysidDefault, pmdp);

	const IMDTypeInt4 *pmdtypeint4 = mda.PtMDType<IMDTypeInt4>();

	CColumnFactory cf;

	// typed colref
	CColRef *pcrOne = cf.PcrCreate(pmdtypeint4);
	GPOS_ASSERT(pcrOne == cf.PcrLookup(pcrOne->m_ulId));
	cf.Destroy(pcrOne);

	// typed/named colref
	CWStringConst strName(GPOS_WSZ_LIT("C_CustKey"));
	CColRef *pcrTwo = cf.PcrCreate(pmdtypeint4, CName(&strName));
	GPOS_ASSERT(pcrTwo == cf.PcrLookup(pcrTwo->m_ulId));

	// clone previous colref
	CColRef *pcrThree = cf.PcrCreate(pcrTwo);
	GPOS_ASSERT(pcrThree != cf.PcrLookup(pcrTwo->m_ulId));
	GPOS_ASSERT(!pcrThree->Name().FEquals(pcrTwo->Name()));
	cf.Destroy(pcrThree);

	cf.Destroy(pcrTwo);

	return GPOS_OK;
}
开发者ID:HanumathRao,项目名称:gporca,代码行数:43,代码来源:CColumnFactoryTest.cpp

示例15:

//---------------------------------------------------------------------------
//	@function:
//		CStackTest::EresUnittest_Pop
//
//	@doc:
//		This test should assert.
//
//---------------------------------------------------------------------------
GPOS_RESULT
CStackTest::EresUnittest_Pop()
{
    // create memory pool
    CAutoMemoryPool amp;
    IMemoryPool *pmp = amp.Pmp();

    ULONG rgsz[] = {1, 2, 3, 4};

    CStack<ULONG> *pstk =
        GPOS_NEW(pmp) CStack<ULONG> (pmp, 4);

    CAutoP<CStack<ULONG> > cAP;
    cAP = pstk;

    // add elements incl trigger resize of array
    for (ULONG i = 0; i < 4; i++)
    {
        pstk->Push(&rgsz[i]);
        GPOS_ASSERT( (* pstk->Peek()) == 4 - i);
        GPOS_ASSERT(pstk->Pop() == &rgsz[i]);
    }

    // now deliberately pop when the stack is empty
    pstk->Pop();

    return GPOS_FAILED;
}
开发者ID:margiex,项目名称:gpos,代码行数:36,代码来源:CStackTest.cpp


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